How does an if else if control structure work?
An if-else-if control structure shifts program control, step by step, through a series of statement blocks. Control stops at the relational expression that is True and executes the corresponding statement block. After execution of the statement block, control shifts to the end of the control structure. If none of the relational expressions is true, the final statement block is executed.
The form of the if else if control structure is:
if (relational_expression_1)
{
statement_block_1
}
else if (relational_expression_2)
{
statement_block_2
}
.
.
.
.
else if (relational_expression_n)
{
statement_block_n
}
else
{
statement_block
}
No comments:
Post a Comment