Introduction of C
programming loops
DHANANJAY PATEL (17TMPA052)
Loops
 Loops statements are used to repeat the execution of statements.
 Types of loops :
• For loop
• While loop
• Do…..While loop
• Nesting for loop
For loop
 For loop has three parts:
• Initializer is executed at start of loop.
• O Loop condition is tested before iteration to decidewhether to continue or terminate the loop.
• O Increment is executed at the end of each loopiteration.
while(condition)
{
….
if(condition)
{
break;
}
…..
}
While Loop
 It has a loop condition only that is testedbefore each iteration to decide whether
tocontinue or terminate the loop.
 Syntex:
while(condition)
{
….
if(condition)
{
break;
}
…..
}
Do…While Loop
 Do while has a loop condition only that is tested aftereach iteration to
decide whether to continue with nextiteration or terminate the loop.
 Syntex:
do
{
…..
if(condition)
{
break;
}
…….
}
while(condition);
Nesting for Loop
 Nesting of for loops means for statement within another for statement.
 Two loops can be nested...
 Example :
for( i=1; i<=n; i++)
{
for(j=1; j<=i; j++)
{
printf(“*”);
}
printf(“n”);
}
Introduction of C programming loops

Introduction of C programming loops

  • 1.
    Introduction of C programmingloops DHANANJAY PATEL (17TMPA052)
  • 2.
    Loops  Loops statementsare used to repeat the execution of statements.  Types of loops : • For loop • While loop • Do…..While loop • Nesting for loop
  • 3.
    For loop  Forloop has three parts: • Initializer is executed at start of loop. • O Loop condition is tested before iteration to decidewhether to continue or terminate the loop. • O Increment is executed at the end of each loopiteration. while(condition) { …. if(condition) { break; } ….. }
  • 4.
    While Loop  Ithas a loop condition only that is testedbefore each iteration to decide whether tocontinue or terminate the loop.  Syntex: while(condition) { …. if(condition) { break; } ….. }
  • 5.
    Do…While Loop  Dowhile has a loop condition only that is tested aftereach iteration to decide whether to continue with nextiteration or terminate the loop.  Syntex: do { ….. if(condition) { break; } ……. } while(condition);
  • 6.
    Nesting for Loop Nesting of for loops means for statement within another for statement.  Two loops can be nested...  Example : for( i=1; i<=n; i++) { for(j=1; j<=i; j++) { printf(“*”); } printf(“n”); }