Skip to main content
To Get All Information of Sarkari Jobs | Results | Admit Card | And courses ,Internships then CLICK HERE

do-while loop-:


do-while is a condition control loop.The do-while loop is used to carry out looping operation,in which a statement or group of statements is/are executed repetitively until some logical condition has been satisfied.
do-while is also called "exit-control loop",because in do-while loop first the statement get executed and then the condition is checked,hence the do-while always execute at least one's.
In the do-while loop, there must be at least one such statement within the body of loop which changes the looping condition,during the execution of loop otherwise an infinite loop may occur.
ads

Syntax-:
do
    statement;
    while(condition);
or,
do
   {statement-1;
     statement-2;
     -
     -
     statement-n;
     }while(condition);
Example-:
Write a program to find sum of series of terms: 2+4+6+8+ - - -n
#include<stdio.h>
#include<conio.h>
main()
{int i=1,term=0,s=0;
  printf("Enter the term");
  scanf("%d",&term);
  do{s=s+(2*i);
          i++;
       }while(i<=term);
  printf("\n sum=%d",s);
  getch();
}
Output-:Enter the term 3
               sum=12
ads Watch The Video Below


Comments

Post a Comment

Please do not enter any spam link in the comment box.


Download The Book "Let Us C" By Yashavant P.Kanetkar,Click The Below Button

-->Email Subscription

Enter Your Email Address:-

Delivered by FeedBurner

Copyright © 2020 TechProgramiz|All Right Reserved|Made By-: Sudarshan Pandey