If...Then...Else: Difference between revisions
m Ghenne moved page If...then...else to If...Then...Else |
Add javascript snippet |
||
Line 15: | Line 15: | ||
To execute multiple statements inline, the statements must be separated by a colon (:). If an inline statement consists of a lone procedure call with no arguments, the procedure must be called with empty parenthesis. | To execute multiple statements inline, the statements must be separated by a colon (:). If an inline statement consists of a lone procedure call with no arguments, the procedure must be called with empty parenthesis. | ||
== Example == | == Example (Basic) == | ||
<pre> | <pre> | ||
Line 27: | Line 27: | ||
Print "Alien Probe" | Print "Alien Probe" | ||
End If | End If | ||
</pre> | |||
== Example (JavaScript) == | |||
<pre> | |||
// If...Then...Else Example | |||
/* If...Then...Else performs conditional execution */ | |||
var Who; | |||
if (true) { NSB.Print("TRUE"); } else { NSB.Print("FALSE"); } | |||
if (Who == "Al") { | |||
NSB.Print("Big Al"); | |||
}else if (Who == "Alien") { | |||
NSB.Print("Alien Probe"); | |||
} | |||
</pre> | </pre> | ||
Revision as of 20:44, 19 May 2013
If condition Then statements [Else elsestatements]
If condition Then
- [statements]
[ElseIf condition-n Then
- [elseifstatements]]...
[Else
- [elsestatements]]
End If
Description
If...Then...Else is used to conditionally execute a group of statements. The required component, condition, can be any expression that evaluates to TRUE or FALSE. If used inline with no else clause, the statements component is required, otherwise, the statements component is optional. If condition evaluates to TRUE or non-zero, any existing statements are executed, if condition evaluates to FALSE or zero, execution branches to the next existing ElseIf clause to evaluate condition-n,or to the Else clause if it is included.
To execute multiple statements inline, the statements must be separated by a colon (:). If an inline statement consists of a lone procedure call with no arguments, the procedure must be called with empty parenthesis.
Example (Basic)
Rem If...Then...Else Example 'If...Then...Else performs conditional execution Dim Who If TRUE Then Print "TRUE" Else Print "FALSE" If Who = "Al" Then Print "Big Al" ElseIf Who = "Alien" Then Print "Alien Probe" End If
Example (JavaScript)
// If...Then...Else Example /* If...Then...Else performs conditional execution */ var Who; if (true) { NSB.Print("TRUE"); } else { NSB.Print("FALSE"); } if (Who == "Al") { NSB.Print("Big Al"); }else if (Who == "Alien") { NSB.Print("Alien Probe"); }
Output
TRUE