C++ control structures, Conditional control statements,
Iterative control statements, Unconditional control statements explain with examples

C++ control structures:
Control structures determine the direction or order in which statements within the block are executed. Control
statements are used to design control structures. In CPP control statements can be classified as
1. Conditional control statements (if, if else, ladder if, switch .. case )
2. Iterative control statements ( for, while, do .. while)
3. Unconditional control statements (goto, continue, break)
(1) Conditional control statements:
Conditional control statements are used to control the flow of control based on condition statement. For
example if , if else, switch etc.
If statement:
Syntax: 1. if (condition)
statement; // simple if statement
2. if (condition ) // if else statement
Statement
else
Statement
3. else if (condition)
Statement
else if (condition)
Statement
else
Statement
The switch statement:
When there are a number of else alternatives as above, way of representing is by the switch
statement.
The general format of a switch statement is
Switch (expression)
{
case value1:
program statement
……
break;
case value2:
program statement
……
break;
case value’n’:
program statement
……
break;
default:
program statement
break;
}
(2) Iterative control statements
for loop:
for (variable = initial ; condition; amount of increment/decrement)
{
Lines to be repeated;
}
while loop:
initial condition
while (condition)
{ stmt;
stmt;
change of the initial condition;
}
do while loop:
{ stmt;
stmt;
}
while (condition);
(3) Unconditional statements:
Unconditional statements are used to transfer the control from one place to other with out any condition. They are generally used to branch or termination process. For example goto, break, continue, and exit;
Syntax: goto – used to branch the control to a particular place
Break – to terminate the iterative statements
Continue – to get the next iterative value
Labels: C++