Menu

#11 Assignments inside conditions

Next_Release
open
5
2002-12-16
2002-12-16
cchris
No

When conditional statements involve complex or
otherwise long to compute expressions, it should be
possible to assign them to a declared variable.
Thus:

if p:=f(x,y)<g(z) or q:=h(x2,y2)=0 then
...
end if.

would mean: p is assigned the value of f(x,y). If the
second part is evaluated, then q is assigned h(x2,y2).
So, if the first conditional clause returns true, q is left as
it was because of short-circuit evaluation.
Same construct would be also valid in elsif and while
statements, but nowhere else.

Discussion

MongoDB Logo MongoDB