If condition Then
Script block 1 here if condition is true
Else
Script block 2 here if condition is false
EndIf
In the above script block we have first tested the condition and if it is TRUE then Script block 1 gets executed and if the condition is FALSE then script block 2 is executed.
Dim n1,n2
n1=25
n2=45
If n1 > n2 Then
Response.Write "Greatest number is" & n1
Else
Response.Write "Greatest number is" & n2
End If
By changing the assigned values to n1 and n2 we can check how the if else control structure works.
Dim n1,n2
n1=-25
n2=-45
If n1 > n2 Then
Response.Write " Greatest number is " & n1
If n1 < 0 Then
Response.Write "First number is a negative number"
End IF
Else
Response.Write "Greatest number is " & n2
End If
Some places we can use ElseIF condition than using more nested If Else condition. Here is an example of uses of ElseIf Condition.
Dim my_num
my_num=40
If my_num < 100 Then
Response.Write "It is less than 100" & "<br>"
If my_num < 50 Then
Response.Write "It is less than 50 also" & "<br>"
End If
ElseIf my_num > 200 Then
Response.Write "It is greater than 200 " & "<br>"
Else
Response.Write "This is greater than 100 but less than 200"&"<br>"
End if
ElseIf belongs to the same If ... End If structure, so it does not require a separate End If. The optional Else branch comes last.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.