?Describe the structure of theif elsestatement.
What will be an ideal response?
?Theifstatement runs a command or a command block only if the conditional expression returns the valuetrue; it does nothing if the condition is false. On some occasions, a user might want to choose between alternate command blocks so that one command block is run if the conditional expression is true, and a different command block is run if the expression is false. The general structure of anifelse statement follows:?if (condition) {commands if condition is true} else {commands if condition is false}?If only a single command is run in response to theifstatement, one can use the following abbreviated form:
if (condition) command if condition is trueelse command if condition is false;?The following example shows anifelse statement that displays two possible alert boxes depending on whether the value of the day variable is Friday or not:
if (day === "Friday") alert("Thank goodness it's Friday")else alert("Today is " + day);?Likeifstatements,ifelsestatements can be nested as in the following code, which chooses between three possible alert boxes:
if (day === "Friday") alert("Thank goodness it's Friday")else {if (day === "Monday") alert("Blue Monday")else alert("Today is " + day);}?Some programmers advocate always using curly braces even if the command block contains only a single command. This practice visually separates oneelseclause from another. Also, when reading through nested statements, it can be helpful to remember that anelseclause usually pairs with the nearest precedingifstatement.
You might also like to view...
Slides can only be printed in expanded view, not in collapsed view
Indicate whether the statement is true or false
Which of the following address ranges should a network administrator deny in the ACL to prevent multicast packets from crossing the WAN interface?
A. 224.0.0.0239.255.255.255 B. 127.0.0.0127.255.255.255 C. 192.168.0.0192.168.255.255 D. 10.0.0.010.255.255.255