The if statement is used to create a decision structure, which allows a program to have one path of execution. The if statement causes one or more statement to execute only when a boolean expression is true.
The below image explain the if-else statement.
A sequence structure is one that comprises instructions that are to be executed sequentially one after the other, with branching off in another direction.
A Selection(sometime it's also called decision too) structure allows for exactly one of a set of sequence to be executed. In selection, a question is asked, and depending on the answer, the program take the second action, after which program move to the next event.
A Iteration or Loop structure comprises a sequence that is to be executed iteratively. Program repeatedly executes the loops.
| Precedence | Meaning |
|---|---|
> |
Greater than |
< |
Less than |
>= |
Greater than or equal to |
<= |
Less than or equal to |
== |
Equal to |
!= |
Not Equal |
Single statement example:
if (experssion)
statement; --> semicolon goes here
More than one statement example:
if (experssion) {
statement; --> semicolon goes here
} else {
statement; --> semicolon goes here
}
Multiple statement example:
if (experssion)
statement;
else if (experssion)
statement;
else
statement;
Or (by using brackets)
if (experssion){ --> open bracket
statement; --> semicolon
} --> closing bracket
else if (experssion){
statement;
}
else {
statement;
}
