If … Then … Else … End If
Top  Previous  Next

If condition Then statement [Else elsestatement

Or, you can use the block form syntax:

If
 condition Then 
statements
[Else
else statements]
End If 


Conditionally executes a group of statements, depending on the value of an expression.

Parameters

condition  
 
Any expression that evaluates to TRUE or FALSE  
 
statement, statements  
 
Statement(s) executed if condition is TRUE.  
 
elsestatement, elsestatements  
 
Statement(s) executed if condition is FALSE.  

Remarks

When executing If, condition is tested. If condition is TRUE, the statements following Then are executed. If condition is FALSE, the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.  
 
Example
 
If a = 0 Then print "OK"  
 
If (a = 0) or (b = 0) Then c = c - 1 Else c = c + 1  
 
if a = 0 Then  
    b = 0  
    c = 0  
Else  
    b = 1  
    c = 1  
End IF  
 
You can nest If statements by placing one If within another:  
 
if a = 0 Then  
    If b = 0 Then  
        c = 0  
    Else  
        c = 1  
    End IF  
End IF