Control Flow Statements

Control Flow Statements

Same Control Flow Statement we can call Programming Constructions. Programming Constructions represent how the program is goin to execute. There are three programming constructions 1. Sequence 2. Selection 3. Iteration

1. Sequence : Without any conditions if the statements are executed then that process is called Sequence.

Example : Accept two numbers display sum of those  or interchange

2. Selection: Based on the condition if the execution control is changed from one place to another place then it is called Selection. For this purpose we can use Conditional Statements.

3. Iteration: Executing some set of Statements number of times is called Iteration or Repetition. For this purpose we can use Looping Statements 

Conditional Statements : based on the condition execution control is changed from one place to another place for this purpose we can use conditional statements if, switch

Syntax-1


if(condition)

   statement;

else

   statement;


Syntax -2 


if(condition)

{

   statements;

}

else if(condition)

{

   statements;

}

.

.

.

.

else

{

   statements;

}



Syntax -3 nested if

if(condition)

{

   Statements;

     if(condiiton)

     {

        Statements;

     }

     else

     {

        Statements;

     }

}

else

{

 statements;

}



switch 


Syntax


   switch(expression)

   {

      case value: statements;

                  break;

      case value: statements;

                  break;

      .

      .

      .

      default: statements;

               break;

   }



Looping Statements(Iteration process)


to execute the set of statements number of times, for this purpose we can usee loops



for loop

while loop

do..while loop



for loop syntax

        1           2  <-------- 4

for(intialization;condition;changing)

{

    statements;3

}



while loop syntax

while(condition)

{

   statements;

}

do..while syntax

do

{

  statements;

}while(condition);



Unconditional statements


1.break

       int i;

       for(i=1;i<=10;i++)

       {

           if(i==5)

             break;

          printf("\n%d",i);

       }

       Outpt :

        1

        2

        3

        4



2.continue

       int i;

       for(i=1;i<=10;i++)

       {

           if(i==5)

             continue;

          printf("\n%d",i);

       }


       Outpt :

        1

        2

        3

        4

        6

        7

        8

        9

       19


3.goto

4.exit

5.return

Comments

Popular posts from this blog

Functions

Example Programs for Control Flow Statements

SQL Operators