top of page

Chapter 10 -Flow of controls

 

Important terms and definitions

1.if statement

 

if is known as conditional control structure or selection structure because 

it checks for the given condition and then selects the particular action or just ignores it.

 

forMAT

if(condition)

{

   Program statements ;

}

 

 

 

For example

if(age<= 21)

{

cout<<"You are a minor.\n";

cout<<"What is ur grade?";

cin>>grade;

 

 

FOR STATEMENT

The for statement encloses one or more C++ statements that form the body  of the loop , the statements in the loop repeat continuously upto certain number of times the loop repeats.The format of the for loop is for initialization

expression[s];text-expression;update expression.

For example,

int ctr;

for[ctr =[ 1; ctr < = 10; ctr = ctr + 1]

{

 

cout << ctr << ";

 

}

 

 

 

 

SWITCH STATEMENT

The switch statement handles a series of decisions by checking a particles variable or expressions for different 

values it may assume and basing upon it,different actions are taken

 

 

 

 

 

 

 

 

 

For example

switch(opt)

{

   case1:cout<<"I am in case 1";

    break;

    case 2:cout<<"I am in case 2";

     break:

     case 3:cout<<"I am in case 3";

     break;

    deafualt:

            cout<<"\n Invalid option select";

]

 

 

 

 

 

 

 

 

 

 

3.WHILE STATEMENT

The while statement is known as entry control loop beacuse it executes a set of statements till the condition  is evaluated as true. The while statement is one of several C++ construct statements .A construct is a programming language statement of a series of statements that control looping

 

 

 

 

 

 

 

For instance 

i=1

while(i<=0)

{

     fact=fact*i;

     i++;

 

 

Do while statement

This loop is similar to the while loop,except that with do-while ,the relational as long as the result is true ,

the body of the loop continues to execute.

For eg

int value;

do

{

cout<<"Enter the number to be reversed.";

cin>>value;

if(value<=0)

                cout<<"The number must be positive \n";

}

while (value<=0)

  • w-facebook
  • Twitter Clean
  • w-googleplus
bottom of page