When a user wants to execute a group of statements depending upon a value of an expression, then he can use Select Case statements. Each value is called a Case, and the variable being switched ON based on each case. Case Else statement is executed if test expression doesn't match any of the Case specified by the user.
Case Else is an optional statement within Select Case, however, it is a good programming practice to always have a Case Else statement.
The syntax of a Select Statement in VBScript is −
Select Case expression Case expressionlist1 statement1 statement2 .... .... statement1n Case expressionlist2 statement1 statement2 .... .... Case expressionlistn statement1 statement2 .... .... Case Else elsestatement1 elsestatement2 .... .... End Select
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim MyVar MyVar = 1 Select case MyVar case 1 Document.write "The Number is the Least Composite Number" case 2 Document.write "The Number is the only Even Prime Number" case 3 Document.write "The Number is the Least Odd Prime Number" case else Document.write "Unknown Number" End select </script> </body> </html>
In the above example, the value of MyVar is 1. Hence, Case 1 would be executed.
The Number is the Least Composite Number