|
|
(8 intermediate revisions by 4 users not shown) |
Line 1: |
Line 1: |
| <pre>
| | If ''condition'' Then ''statements'' [Else ''elsestatements''] |
| IF ''condition'' THEN ''statements'' [ELSE ''elsestatements'']
| |
|
| |
|
| IF ''condition'' THEN
| | If ''condition'' Then |
| | :[''statements''] |
| | [ElseIf ''condition-n'' Then |
| | :[''elseifstatements'']]... |
| | [Else |
| | :[''elsestatements'']] |
| | End If |
|
| |
|
| [''statements'']
| | == Description == |
|
| |
|
| [ELSEIF ''condition-n'' THEN
| | 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. |
|
| |
|
| [''elseifstatements'']]...
| | 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. |
| | |
| [ELSE
| |
|
| |
|
| [''elsestatements'']]
| | == Example == |
|
| |
|
| END IF
| | <tabber> |
| </pre> | | JavaScript= |
| | <syntaxhighlight lang="JavaScript"> |
| | // If...Then...Else Example |
| | /* If...Then...Else performs conditional execution */ |
|
| |
|
| '''Description''' | | 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"); |
| | } |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| | 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 |
| | </syntaxhighlight> |
| | </tabber> |
|
| |
|
| 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.
| | == Output == |
| | |
| 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'''
| |
|
| |
|
| <pre> | | <pre> |
| REM IF...THEN...ELSE Example
| | TRUE |
| '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
| |
| </pre> | | </pre> |
|
| |
|
| '''Output'''
| | == Related Items == |
|
| |
|
| <pre>
| | [[select case|Select Case]] |
| TRUE
| |
| </pre>
| |
|
| |
|
| '''Related Items'''
| | [[Category:Language Reference]] |
|
| |
|
| [[select case|SELECT CASE]] | | [[Category:Statements - Flow of control]] |
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
// 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");
}
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
Output
TRUE
Related Items
Select Case