Conditional statements are used to perform different actions for different decisions.
In VBScript we have four conditional statements:
Use the If...Then...Else statement if you want to
If you want to execute only one statement when a condition is true, you can write the code on one line:
There is no ..Else.. in this syntax. You just tell the code to perform one action if a condition is true (in this case If i=10).
If you want to execute more than one statement when a condition is true, you must put each statement on separate lines, and end the statement with the keyword "End If":
There is no ..Else.. in the example above either. You just tell the code to perform multiple actions if the condition is true.
If you want to execute a statement if a condition is true and execute another statement if the condition is not true, you must add the "Else" keyword:
In the example above, the first block of code will be executed if the condition is true, and the other block will be executed otherwise (if i is greater than 10).
You can use the If...Then...ElseIf statement if you want to select one of many blocks of code to execute:
You can also use the "Select Case" statement if you want to select one of many blocks of code to execute:
This is how it works: First we have a single expression (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each Case in the structure. If there is a match, the block of code associated with that Case is executed.
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.