Lesson 8: Conditional
Statements
If Statement:
You
should use the if statement if you want to execute some code if a condition
is true.
if
(condition) {code to be executed if condition is true}
If... Else Statement:
If
you want to execute some code if a condition is true and another code
if a condition is false, use the if....else statement.
if
(condition) {code to be executed if condition is true}
else
{code to be executed if condition is false}
Switch Statement:
You should use the Switch statement if you want to select one of
many blocks of code to be executed.
switch
(expression)
{case label1:
code to be executed if expression = label1
break
case label2:
code to be executed if expression = label2
break
default:
code to be executed
if expression is different
from both label1 and label2}