Thursday, July 11, 2019

Looping Statement in C

Looping Statement in c:



 The loop controls are as follows:

  1.For loop
  2.while loop
  3.do while loop



 1]. For Loop:

The for loop is used to execute the statement specific number of time.

A for loop is a repetition control structure that allows you to traverse a element specific number of time.

  Syntax Of For Loop:

  for(init; condition; increment)
  {
  //Code tro be executed.
  }

init: The init steps is used to intialize the value to the variable.This step is executed first when you uses the for loop.

Condition: In next step if the condition define by user is true then the body of the loop will be executed.

Increment: After both of step the value of the variable should be incremented or decremented.
 

2] While Loop:

While loop is also known as a pre-tested loop. while loop is used to execute the code multiple time.

 While loop ewxecutes the code repeatilly as long as the condition becomes true.

  Syntax of while loop:

  while(Condition)
  {
  //Statement to be executed;
  }

 3] Do-while loop:

The do-while is a post tested loop.we can repeatthe execution of specific parts of the statement.he do-while loop is mostly used in menu-driven programs.

 do-while loop checks its condition at the bottom of the loop.

  Syntax of Do-while:
 
                     do
  {
    //statement to be executed;
  }
  while(Condition);


EmoticonEmoticon