Presentationnested loopsBy:- Balwinder Singh
     contentsWhat is a Loop?
Nested While loops.
Do…..While loops.
Nested For loops.
Question.     What is a loop?A loop is a programming structure that contains an executable block of code that repeats so long as a given condition is true/not true.
Good programmers include a way to satisfy the condition somewhere inside the executable block.loops
     Types of nested loopsNested While Loops.
Do…..While Loops.
Nested For Loops.nested loops
      Nested while loopsWHILE loops may be nested, that is you can put a WHILE loop inside another WHILE loop.
 However, one must start the inner loop after starting the outer loop and end the inner loop before ending the outer loop for a logically correct nesting.      Example:- nested while loopsTo print the following series:-11   21   2   31   2   3   41   2   3   4   5
      Example:- nested while loops#include<stdio.h>#include<conio.h>main(){ int r=1,c=1;	while (r<=5)	{		c=1;		while(c<=r)		{printf(“%d”,c);c++;		      }printf(“\n”);		r++;		}getch();}
Do……while loopExecutes the loop statement once and then repeats the loop statement until the condition is zero (false).

Presentation on nesting of loops

  • 1.
  • 2.
    contentsWhat is a Loop?
  • 3.
  • 4.
  • 5.
  • 6.
    Question. What is a loop?A loop is a programming structure that contains an executable block of code that repeats so long as a given condition is true/not true.
  • 7.
    Good programmers includea way to satisfy the condition somewhere inside the executable block.loops
  • 8.
    Types of nested loopsNested While Loops.
  • 9.
  • 10.
  • 11.
    Nested while loopsWHILE loops may be nested, that is you can put a WHILE loop inside another WHILE loop.
  • 12.
    However, onemust start the inner loop after starting the outer loop and end the inner loop before ending the outer loop for a logically correct nesting. Example:- nested while loopsTo print the following series:-11 21 2 31 2 3 41 2 3 4 5
  • 13.
    Example:- nested while loops#include<stdio.h>#include<conio.h>main(){ int r=1,c=1; while (r<=5) { c=1; while(c<=r) {printf(“%d”,c);c++; }printf(“\n”); r++; }getch();}
  • 14.
    Do……while loopExecutes theloop statement once and then repeats the loop statement until the condition is zero (false).