FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
510 views
in RTU/BTU B.Tech(CSE-I & II Sem) Computer Programming Lab by Goeduhub's Expert (7.6k points)
Programs to learn iterative statements like while and do-while loops.

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.6k points)
edited by
 
Best answer

Programs to learn iterative statements like while and do-while loops.

Difference between While and Do-While loop : 

While Do-While
In 'while' loop the controlling condition appears at the start of the loop.In 'do-while' loop the controlling condition appears at the end of the loop.
The iterations do not occur if, the condition at the first iteration, appears false.The iteration occurs at least once even if the condition is false at the first iteration.
Entry-controlled loopExit-controlled loop
Semicolon is not usedSemicolon is used at the end of the loop
while ( condition) 
{
statements; 
}
do{
statements;
} while( Condition );

 

While Loop : A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

  • The while loop evaluates the test expression inside the parenthesis ().
  • If the test expression is true, statements inside the body of while loop are executed. Then, the test expression is evaluated again.
  • The process goes on until the test expression is evaluated to false.
  • If the test expression is false, the loop terminates (ends).

Syntax : 

while (condition )
{
      //Statements to be executed 

}

 Example : 

#include<stdio.h>

#include<conio.h>

void main()

{

    int i = 1; 

    while (i <= 5)

    {

        printf("%d\n", i);

        ++i;

    }    

}

Output : 

1

2

3

4

5


Do-While loop : do while loop is similar to while loop with the only difference that it checks for the condition after executing the statements, and also Exit Control Loop.

  • The body of do...while loop is executed once. Only then, the test expression is evaluated.
  • If the test expression is true, the body of the loop is executed again and the test expression is evaluated.
  • This process goes on until the test expression becomes false.
  • If the test expression is false, the loop ends.

Syntax :

do

{

// statements to be executed

}

while (Condition);

Example : 

#include<stdio.h>

#include<conio.h>

void main()

{

    int i=0;

do

{

printf("Value of i is: %d\n", i);

i++;

}while (i<=3);

}

Output : 

Value of i is: 0

Value of i is: 1

Value of i is: 2

Value of i is: 3


For more RTU/BTU II Sem Computer Programming Lab  Experiments CLICK HERE

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...