Bill Allombert on Wed, 12 Jan 2022 10:20:11 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: forbidden comparison |
On Wed, Jan 12, 2022 at 04:14:47AM +0100, Ruud H.G. van Tol wrote: > > I expected this to just work: > > my(v=23, c3=7); while( my(c=c3*2); c < v, c3=c ); print([v,c3]); > > > Now changed it to; > > my(v=23, c3=7);while( c3*2 < v, c3*=2 ); print([v,c3]); > [23, 14] > > > With 'if', this works: > > ? my(v=23, c3=7); if(my(c=c3*2)*0+c, print(c)) > 14 > > but while has an extra scope? Because the condition in 'while' is evaluated several times, while for 'if' it is evaluated only once, so there is no deferred execution involved. Cheers, Bill