Conditional structures: Difference between revisions

Content added Content deleted
(added MiniScript example)
Line 3,544: Line 3,544:


'''XX''' here is the address to which to make the jump in the event of failure of this condition (for this reason, these instructions are also called checks).
'''XX''' here is the address to which to make the jump in the event of failure of this condition (for this reason, these instructions are also called checks).

=={{header|MiniScript}}==
MiniScript supports if/else-if/else, with arbitrary number of else-if sections when in block form:

<lang MiniScript>x = 42
if x < 10 then
print "small"
else if x < 20 then
print "small-ish"
else if x > 100 then
print "large"
else
print "just right"
end if</lang>

It also supports single-line if or if/else statements (though no else-if sections are permitted in this case):

<lang MiniScript>x = 42
if x < 50 then print "small" else print "big"</lang>

Finally, like many other languages, MiniScript uses short-circuit evaluation, a form of implicit branching where the rest of a boolean expression is not evaluated at all if the truth value can already be determined.

<lang MiniScript>isSmall = function(x)
print "checking smallness"
return x < 40
end function

isBig = function(x)
print "checking bigness"
return x > 60
end function

isSmall(10) or isBig(100)</lang>

{{out}}
<pre>checking smallness</pre>



=={{header|Modula-2}}==
=={{header|Modula-2}}==