The if...else Statement
Use the if....else statement to execute some code if a condition is true and another code if a condition is false.
Syntax
if (condition)
code to be executed if condition is true;
else
code to be executed if condition is false;
Example
The following example will output "Have a nice weekend!" if the current day is Friday, otherwise it will output "Have a nice day!":
html
body
body
html
If more than one line should be executed if a condition is true/false, the lines should be enclosed within curly braces:
html
body
body
html
No comments:
Post a Comment