Conditional structures: Difference between revisions

Content deleted Content added
m Breaking up alternatives in AutoHotkey to headers sections.
→‎Nemerle: if-else: corrected inaccurate text; formatting
Line 2,086: Line 2,086:
=={{header|Nemerle}}==
=={{header|Nemerle}}==
===if-else===
===if-else===
'''if (cond) <then> else <this>;''' is an expression in Nemerle, producing side effects (<then>|<this>) but not evaluating to anything. '''when''' and '''unless''' are macros for which <this> = null. '''cond''' must be an expression that evaluates to a bool (true|false), other types aren't automatically assigned truth or falsehood as in some languages.
<tt>if (cond) <then> else <this>;</tt> is an expression in Nemerle, requiring both keywords (<tt>if</tt> and <tt>else</tt>) to be 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();
<lang Nemerle>if (the_answer == 42) FindQuestion() else Foo();
when (stock.price < buy_order) stock.Buy();
when (stock.price < buy_order) stock.Buy();
unless (text < "") Write(text);</lang>
unless (text < "") Write(text);</lang>

===match===
===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].
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].