Microsoft® JScript if...else Statement |
| Language Reference |
|
Conditionally executes a group of statements, depending on the value of an expression.
if (condition)The if...else statement syntax has these parts:
statement1
[else
statement2]
Part | Description |
condition | A Boolean expression. If condition is
null or undefined, condition is treated as false.
|
statement1 | The statement to be executed if condition is true. Can be a compound statement. |
statement2 | The statement to be executed if condition is false. Can be a compound statement. |
It is generally a good idea to enclose statement1 and statement2 in braces ('{}') for clarity and to avoid inadvertent errors. For the following example you may want the else to be used with the first if statement, but it is used with the second one.
if (x == 5) if (y == 6) z = 17; else z = 20;Changing the code to read:if (x == 5) { if (y == 6) z = 17; } else z = 20;eliminates any ambiguities.Later on, if you wanted to add a statement to statement1, and you didn't use the braces, you could accidentally create an error:
if (x == 5) z = 7; q = 42; else z = 19;In this case, there is a syntax error, as there is more than one statement between the if and else statements. Putting braces around the statements between the if and else is required.
© 1996 by Microsoft Corporation.
file: /Techref/language/asp/js/208.htm, 3KB, , updated: 1996/11/22 10:11, local time: 2024/12/21 06:29,
18.117.71.47:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://massmind.org/Techref/language/asp/js/208.htm"> Microsoft® JScript Language Reference </A> |
Did you find what you needed? |
Welcome to massmind.org! |
Welcome to massmind.org! |
.