- if - to execute code only a specified condition is TRUE.
- if..else - to execute code if a condition is TRUE, and another code if a condition is FALSE.
- if..elseif..else - to select one of several blocks of code to be executed.
- switch - to select one of many blocks of code to be executed.
The if Statement
The following example will output "Lets go holiday!" if the current day is Saturday:
(click image to view)
The if..else Statement
The following example will output "Lets go holiday!" if the current day is Saturday, otherwise it will output "Lets do our own work!":
(click image to view)
Now, we try to execute more than one line if a condition is true. The lines should be enclosed within curly braces:
(click image to view)
The if..elseif..else Statement
The following example will output "Lets go holiday!" if the current day is Saturday, and "Having fun with friends!" if the current day is Sunday. Otherwise it will output "Have a nice day, my friends!":
(click image to view)
No comments:
Post a Comment