CONTROL STRUCTURE in C++ | Basic IT Topic

CONTROL STRUCTURE in C++

control structure in C++

CONTROL STRUCTURE in C++:-

A control structure is a block of programming that analyzes variables and determines the order in which statements are executed.

Loop Control Structure:-

For

For(initialize counter; test condition; re-evaluation parameter)

{

Statement;

Statement;

}

While

while(test condition)

{

Body of loop

}

 

Do-while

do

{

statement;

}

while(condition)

Selection Control Structure:-

Switch case

Switch(variable)

{

Case constant A;

Statement;

Break;

Case constant B;

Statement;

Break;

Default;

Statement;

}

Default

 

Decision Control Structure:-

If:-

if(condition)

Statement;

If Else

If (condition)

{

Statement 1;

Statement 2;

}

else

{

Statement 3;

Statement 4;

}

Break statement

Break;

Continue statement;

Continue;

Default;

Jump Control Structure:-

Go to

goto label;

Some tips on Control Structure:-

If statement is used for checking range and yes/no problem

else is the optional part of the if

Execution of switch case starts from the match case.

Use break to prevent the falling of control from one case to another case.

If none of the cases are satisfied then default case will be satisfied.

Case character only can be integral constant.

Switch case only checks integral does not check the float.

Continue cannot be the part of the switch case.

Switch without case no use ( no output no error).

Switch case is the replacement of if…else statement.

Switch case is used for selection control statement.

Loop counter can be int, char and float.

If loop counter is not initialized in a loop , that is called odd loop.

Loop is an alternate of function recursion and function recursion is an alternate of loop.

For loop is suitable for finite loop , while loop is suitable for unknown loop and do while loop is suitable for at least once.

Loop counter has its own block scoping.

Drop all the parts of for loop is an infinite loop but drops all part of while and do while loop is an error.

break in loop transfer control outside the loop.

Continue transfer the control to beginning of loop.

If loop counter exceeds its range , it will be infinite loop.

Every loop has start value, step value and stop value.

If loop loses its step value , it will be an infinite loop.

Repeating some parts of program and Software delay use loop.

Loop is faster than function recursion.

 

Also Read:- Datatype in C++

basicittopic

basicittopic

A Computer Science Study for IT students and people of IT community