If statement
The if ststement is a powerful decision-making ststement and is used to control the flow of execution of statements. It is basically a two-way decision statement and is used in conjuction with an expression
SIMPLE IF STATEMENT
if (test expression)
{
statement-block;
}
statement-x;
THE IF......ELSE STATEMENT
if (test expression)
{
True-block statement(s)
}
else
{
False-block statement(s)
}
statement-x
THE ELSE IF LADER
if (condition 1)
statement-1;
else if (condition 2)
statement-2;
else if (condition2)
statement-3;
else
default-ststement;
statement-x;
THE SWITCH STATEMENT
The switch statements tests the value of a given variable (or expression) against a list of case values and when a match is found , a block of statements associated with that case is executed. The general form of the switch statement is
switch (expression)
{
case value-1:
block-1
break;
case value-2:
block-2
break;
default:
default-block
break;
}
statemeny-x;
Rules for switch Statement
1. The switch expression must be an integral type.
2. Case labels must be constants or constant expressions.
3. Case label must be unique.
4. It is permitted to nest switch statements
5. There can be at most one default label
6.The default may be placed anywhere but uually placed at the end
No comments:
Post a Comment