[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: assignment in conditional expression?
- From: lhf@... (Luiz Henrique de Figueiredo)
- Date: Tue, 8 Dec 1998 09:42:07 -0200 (EDT)
>From: David Jeske <email@example.com>
>Is there any way to do assignment inside an expression? I often want
>to do this in if or while blocks and whenever I try something like:
>if ((a = fn()) == 2) then
>while (a = fn()) do
>it (of course) dosn't work.. Is there some way to do assignment inside
>an expression like this, and if not, why not?
assignments are statements, not expressions as in C.
but, if 'a' is a global variable, you can d:
while (setglobal("a",f())==2) do ... end
mind you, setglobal("a",f()) is probably *not* noticably slower than a=f()!