89Chapter 6Control and FunctionsIf-elseThe syntax for (Web hosting faq) ifis: if

89Chapter 6Control and FunctionsIf-elseThe syntax for ifis: if (test) statement-1Or with an optional elsebranch: if (test) statement-1elsestatement-2When an ifstatement is processed, the testexpression is evaluated, and the result is inter- preted as a Boolean value. If testis true, statement-1is executed. If testis not true, andthere is an elseclause, statement-2is executed. If test is false, and there is no elseclause, execution simply proceeds with the next statement after the ifconstruct. Note that a statementin this syntax can be a single statement that ends with a semicolon, abrace-enclosed block of statements, or another conditional construct (which itself counts asa single statement). Conditionals can be nested inside each other to arbitrary depth. Also, theBoolean expression can be a genuine Boolean (TRUE, FALSE, or the result of a Boolean opera- tor or function), or it can be a value of another type interpreted as a Boolean. For the full story on how values of non-Boolean types are treated as Booleans, see Chapter 25. The short version is that the number 0, the string 0 , and the empty string, , are false, andalmost every other value is true. The following example, which prints a statement about the absolute difference betweentwonumbers, shows both the nesting of conditionals and the interpretation of the test asaBoolean: if ($first - $second) if ($first > $second) { $difference = $first - $second; print( The difference is $difference
); } else{ $difference = $second - $first; print( The difference is $difference
); } elseprint( There is no difference
); This code relies on the fact that the number 0is interpreted as a false value if the differ- ence is zero, then the test fails, and the no differencemessage is printed. If there is a difference, a further test is performed. (This example is artificial, because a test like $first!=$secondwould accomplish the same thing comprehensibly.) Cross- Reference08
Note: If you are looking for high quality webhost to host and run your jsp application check Vision florida web design services

Leave a Reply