Unless
(Created page with "= Unless...ElseIf...Else...EndIf = === Description === Conditionally run statements. <pre> Unless <expression> Then statements ... [ElseIf expression-n Then [else...") |
m (1 revision) |
||
(8 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | = Unless... | + | = Unless...Else Unless...Else = |
=== Description === | === Description === | ||
Line 6: | Line 6: | ||
<pre> | <pre> | ||
− | Unless <expression> | + | Unless(<expression>) |
+ | { | ||
statements | statements | ||
... | ... | ||
− | + | } | |
− | + | Else If(expression-n) | |
+ | { | ||
+ | else if statements | ||
... | ... | ||
− | + | } | |
− | + | Else Unless(expression-n) | |
+ | { | ||
+ | else if statements | ||
... | ... | ||
− | + | } | |
+ | Else | ||
+ | { | ||
+ | else statements | ||
+ | ... | ||
+ | } | ||
</pre> | </pre> | ||
Line 22: | Line 32: | ||
==== expression ==== | ==== expression ==== | ||
− | If the expression is false, the first statement block is executed. If not, the first true | + | If the expression is false, the first statement block is executed. If not, the first true Else If block is executed or the first false Else Unless block is executed. Otherwise, the "Else" block is executed. |
+ | |||
+ | All the Else If, Else Unless and Else blocks are optional. | ||
=== Remarks === | === Remarks === | ||
Line 28: | Line 40: | ||
Unless statements may be nested. | Unless statements may be nested. | ||
− | + | Its worth noting you can use Else Ifs and Else Unless together with no problem. | |
− | The expression can contain the boolean operators of | + | The expression can contain the boolean operators of &&, ||, ! as well as the logical operators <, <=, >, >=, ==, !=, <>, eq, eqi, neq and neqi as needed grouped with parentheses as needed. |
=== Example === | === Example === | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | Unless $a == 100 | + | Unless($a == 100) |
− | println( "Value is 100" ) | + | { |
− | + | println( "Value is NOT 100" ); | |
− | println( "Value is 200" ) | + | } |
+ | Else If($a == 200) | ||
+ | { | ||
+ | println( "Value is 200" ); | ||
+ | } | ||
+ | Else Unless($a == 44) | ||
+ | { | ||
+ | println( "Value is NOT 44" ); | ||
+ | } | ||
Else | Else | ||
− | println( "No Match" ) | + | { |
− | + | println( "No Match" ); | |
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example of using the logical | + | Example of using the logical !? : operator: |
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | + | println( $a == 100 !? "Value is NOT 100" : "The value is 100" ); | |
− | println( " | + | </syntaxhighlight> |
− | + | ||
− | println( " | + | The !? : operator is much faster than a full UNLESS statement so if you want more speed in your programs this is a rather good choice for simple Unless. |
− | + | ||
− | println( " | + | Can be used to set variables: |
− | + | ||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $var = $a == 100 !? "Value is NOT 100" : "The value is 100"; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | An IF can also be used by itself example | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $a = 10; | ||
+ | unless($a == 10) | ||
+ | println("It is NOT 10"); | ||
+ | |||
+ | // Or even | ||
+ | $a = 10; | ||
+ | unless($a == 10) | ||
+ | println("It is NOT 10"); | ||
+ | else | ||
+ | println("It is 10"); | ||
+ | |||
+ | // Or Even | ||
+ | $a = 10; | ||
+ | unless($a == 10) | ||
+ | println("It is NOT 10"); | ||
+ | else unless($a == 11) | ||
+ | println("It is NOT 11"); | ||
+ | else | ||
+ | println("Else"); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | This can also be done in reverse just for the IF itself example | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | println("It is NOT 10") unless($a == 10); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:38, 14 June 2015
Contents |
Unless...Else Unless...Else
Description
Conditionally run statements.
Unless(<expression>) { statements ... } Else If(expression-n) { else if statements ... } Else Unless(expression-n) { else if statements ... } Else { else statements ... }
Parameters
expression
If the expression is false, the first statement block is executed. If not, the first true Else If block is executed or the first false Else Unless block is executed. Otherwise, the "Else" block is executed.
All the Else If, Else Unless and Else blocks are optional.
Remarks
Unless statements may be nested.
Its worth noting you can use Else Ifs and Else Unless together with no problem.
The expression can contain the boolean operators of &&, ||, ! as well as the logical operators <, <=, >, >=, ==, !=, <>, eq, eqi, neq and neqi as needed grouped with parentheses as needed.
Example
Unless($a == 100) { println( "Value is NOT 100" ); } Else If($a == 200) { println( "Value is 200" ); } Else Unless($a == 44) { println( "Value is NOT 44" ); } Else { println( "No Match" ); }
Example of using the logical !? : operator:
println( $a == 100 !? "Value is NOT 100" : "The value is 100" );
The !? : operator is much faster than a full UNLESS statement so if you want more speed in your programs this is a rather good choice for simple Unless.
Can be used to set variables:
$var = $a == 100 !? "Value is NOT 100" : "The value is 100";
An IF can also be used by itself example
$a = 10; unless($a == 10) println("It is NOT 10"); // Or even $a = 10; unless($a == 10) println("It is NOT 10"); else println("It is 10"); // Or Even $a = 10; unless($a == 10) println("It is NOT 10"); else unless($a == 11) println("It is NOT 11"); else println("Else");
This can also be done in reverse just for the IF itself example
println("It is NOT 10") unless($a == 10);