Breaking News

Introduction of Control Structure In C++

Statements are the instructions given to the computer to perform any kind of action, be it data movements, be it making decisions, or be in repeating action.
 
Various statements provided in C++ :
 
Selection statement
 
The selection statement allow you to choose the set of instructions for execution depending upon an expression value.
 
a) if-else statement:
 
It shows that the condition is checked in if statement if it returns the value true then it execute the statements inside the braces.
 
If it returns false value the automatically the statements in else condition are executed.
 
Syntax
 
if( expression )
{
statements;
}
else
{
statements;
}
program.
 
b) Switch statements:
 
C++ provides a multiple branch selection statements known as switch. This selection statement test the value of an expression against the value of the expression.
 
Syntax
 
switch(expression)
{
case 1:
case 2:
………
}
 
Iteration statement
 
The iteration statements allows a set of instructions to be performed repeatedly until a certain condition to be fulfilled.
 
The iteration statements are also called looping statements. Some of the Iteration statement described here
 
a) The for loop:
 
The for loop is easiest to understand of the C++ loops. All its loop controls are gathered at one place.
 
Syntax
 
for( initialization, increment/decrement, termination condition)
 
{
………….
……….
}
 
b) The While loop:
 
The second Loop available in C++ is the while loop. The while loop is entry controlled loop.
 
Syntax
 
while(expression)
{
loop body
}
 
Jump statement
 
The jump statement unconditionally transfer the program control within a function. C++ has four statements that perform an unconditional branch.
 
a) The goto statement:
 
The goto statement can transfer a program control any where in the program. The target destination of goto statement is marked by a label.
 
Syntax
 
goto label;
:
:
label:
 
b) The Break statement:
 
The break statement enables a program to skip over part of the code. A break statement terminates the smallest enclosing while, do-while, for or switch statement.
 
Syntax
 
for(;;)
{
….
continue;
……
}
 
d) Exit statement:
 
Like break one can get out of the loop you can get out of the program by using a library function exit().
 
This function causes the program to terminate as soon as it encountered.

Check Also

Insertion & Extraction In C++

Insertion is the operation of sending characters to a stream, expressed by the overloaded insertion …