Conditional structures: Difference between revisions

Content added Content deleted
m (Breaking up alternatives in AutoHotkey to headers sections.)
(→‎Nemerle: if-else: corrected inaccurate text; formatting)
Line 2,086:
=={{header|Nemerle}}==
===if-else===
'''<tt>if (cond) <then> else <this>;'''</tt> is an expression in Nemerle, producingrequiring sideboth effectskeywords (<thentt>|if<this/tt>) butand not evaluating<tt>else</tt>) to anythingbe valid. '''<tt>when'''</tt> and '''<tt>unless'''</tt> are macros for which <this> = null. '''<tt>cond'''</tt> must be an expression that evaluates to a bool (true|false), other types aren't automatically assigned truth or falsehood as in some languages.
<lang Nemerle>if (the_answer == 42) FindQuestion() else Foo();
when (stock.price < buy_order) stock.Buy();
unless (text < "") Write(text);</lang>
 
===match===
Much cleaner than stacked if-else's, similar in some ways to switch-case (but more flexible). See [http://nemerle.org/wiki/index.php?title=Quick_Guide#Pattern_Matching here], [http://nemerle.org/wiki/index.php?title=Grok_Variants_and_matching#Matching here], or, for extra detail, [http://nemerle.org/wiki/index.php?title=Patterns_%28ref%29 the reference].