Professional Documents
Culture Documents
If Statement
If Statement
If Statement
Syntax 1
If condition then
Execute this line if the condition is true
End if
Example:
X=5
Y=0
If x>0 then
Y= x+3
End if
(y will be 8 if x is greater than 0; Y will remain zero is x is less than or equal to 0.)
Syntax 2
If condition then
Statement to execute if condition is true
Else
Statement to execute if condition is false
End if
Example
If x>0 then
Y=5
Else
Y=-5
End if
(y is 5 if x is greater than 0, else y is -5)
Syntax 3
If condition1 then
Statement if condition 1 is true
Elseif condition2 then
Statement if condition2 is true
Else
Statement if both condition1 and condition2 are false
End if
Example
If x<0 then
Print negative
Elseif x>0 then
Print positive
Else
Print Zero is neither negative nor positive
End if
Syntax 4
If condition1 then
If condtion2 then
Statement if condition1 and condition2 are true
Else
Statement if condition1 is true but condition is false
End if
Else
Statement if condition1 is false
End if
Example
If x>0 then
If x<100 then
Y=300
Else
Y=0
End if
Else
Y=200
End if