These statements are conditional statements and can route the flow of program to different paths
If (condition) {
// statements to be executed when condition is true
} else {
// statements to be executed when condition is false
}
If an if-else statement is used inside another if or else block, it is said to be nested if-else.
If (condition) {
...
If (condition-two) {
...
} else
{
...
}
...
} else
{
...
}
It is a sequence of if-else-if statements that are evaluated in the given order. If a condition is evaluated to be true then all following if-else statements are skipped
Note: The order of execution is: if -> else if -> else if -> … -> else.
Note: Control will come out of chain after execution of matched block.
If (condition) {
...
} else if (condition-two) {
...
} else if (condition-three) {
...
} else {
...
}
Knowledge2life!
Knowledge2life!
|