Looping statement in C Programming

Posted on

Looping assertion

Looping assertion are the statements execute a number of assertion repeatedly a number of variety of instances. In C programming language there are three kinds of loops; whereas, for and do-while.

Why use loop ?

When you could execute a block of code a number of variety of instances then you could use looping idea in C language.

Benefit with looping assertion

  • Scale back size of Code
  • Take much less reminiscence house.
  • Burden on the developer is lowering.
  • Time consuming course of to execute this system is diminished.

loop - Looping statement in C Programming

Kinds of Loops.

There are three sort of Loops out there in ‘C’ programming language.

  • whereas loop
  • for loop
  • do..whereas

Distinction between conditional and looping assertion

Conditional assertion executes solely as soon as in this system the place as looping statements executes repeatedly a number of variety of time.

Whereas loop

In whereas loop First test the situation if situation is true then management goes contained in the loop physique different smart goes outdoors the physique. whereas loop can be repeats in clock smart route.

while loop - Looping statement in C Programming

Syntax

Observe: If whereas loop situation by no means false then loop grow to be infinite loop.

Instance of whereas loop

Output

For loop

for loop is an announcement which permits code to be repeatedly executed. For loop comprises 3 components Initialization, Situation and Increment or Decrements.

for loop - Looping statement in C Programming

Instance of for loop

Output

do-while

A do-while loop is much like some time loop, besides {that a} do-while loop is execute not less than one time.

A do whereas loop is a management stream assertion that executes a block of code not less than as soon as, after which repeatedly executes the block, or not, relying on a given situation on the finish of the block (in whereas).

Syntax

do while loop - Looping statement in C Programming

When use do..whereas Loop

When we have to repeat the assertion block not less than 1 time then we use do-while loop.

Instance of do..whereas loop

Output

Nested loop

In Nested loop one loop is place inside one other loop physi
que.

When we have to repeated loop physique itself n variety of instances use nested loops. Nested loops could be design upto 255 blocks.