Which is better ? While loop or do while loop. Why ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 8

Which is better ? While loop or do while loop. Why ?

In do while loop if the expression is false also it will get printed atleast once. But in while loop is the expression is false then the loop gets terminated.

11th Nov 2019, 1:14 PM
lavanya meghana kadam
lavanya meghana kadam - avatar
18 Answers
+ 7
I hate do while loop *Exit controlled loop *Post tested *Runs atleast once even if it's condition is true or false *writing the body inside statment without knowing the condition first. and making the condition at the end Every thing has own advantage and disadvantage But in most cases do while not so powerful, some may say it's not a standard way to code using do while . I prefer for and while loop Even while loop also have some disadvantages . But comparing while and do while While is more better than do while
13th Nov 2019, 1:25 AM
Charan Leo25
Charan Leo25 - avatar
+ 4
https://code.sololearn.com/cVbstyuLlINs In the above code why the count value 8 is not going to print ?
11th Nov 2019, 1:24 PM
lavanya meghana kadam
lavanya meghana kadam - avatar
+ 4
It depends on the code you're writing. Do while loop runs the code at least once before testing it, and while loop tests it and then runs it
12th Nov 2019, 11:04 PM
Dina Srabović
Dina Srabović - avatar
+ 3
Change to count<=8. Loop exiting when count =8, hence will not repeat.
11th Nov 2019, 1:27 PM
Jayakrishna 🇮🇳
+ 3
They both perform different task so we can't say which one is better
12th Nov 2019, 6:17 PM
Ali Farhad
Ali Farhad - avatar
+ 3
Both of them have their importance. Which one is good at which logic It's all depend Because some time we want our code run at least once before checking a condition so we prefer to use do- while In some case we want to check 1st condition then we opt while loop
13th Nov 2019, 8:02 AM
Pooja - avatar
+ 2
While loop because Python does not have do while loop.
11th Nov 2019, 3:09 PM
Seb TheS
Seb TheS - avatar
+ 2
Do while is best but for long program For short problem while lope is best💻🖥️
12th Nov 2019, 3:28 PM
Abdul Wahab Chattha
Abdul Wahab Chattha - avatar
+ 2
It depends on what you want to use it for. A while loop won't run if the condition is false, but a do-while loop will run at least once before it is terminated.
12th Nov 2019, 3:44 PM
+ 2
I prefer While loop as it checks the condition first and then goes into the loop.
13th Nov 2019, 8:44 AM
AchyutMS - avatar
+ 2
It depends on the program If it is necessary to run the instructions at least one time in the given program ,then we must use do while Otherwise while is enough But,we can't say which is better for use it depends on the program .
13th Nov 2019, 1:14 PM
+ 1
You need to count=8 Or count<9
12th Nov 2019, 3:35 PM
Abdul Wahab Chattha
Abdul Wahab Chattha - avatar
+ 1
As do while is prefer when you want to run the program at least once .but while much easygoing
13th Nov 2019, 3:53 AM
Nasreen Bano Quraishi
Nasreen Bano Quraishi - avatar
+ 1
while is semple
13th Nov 2019, 10:54 AM
Saud ALhasawi
Saud ALhasawi - avatar
while is an entry controlled loop, *while* do-while is an exit controlled loop structure.
12th Nov 2019, 10:50 PM
Anup Kale
Anup Kale - avatar
Do you get to Know difference between do while and while
14th Nov 2019, 12:50 PM
for is usually used for a countable number of iterations while and do..while loops are used when we have conditional execution. Do..while just makes sure you do something atleast once. Eg. Printing a menu While makes sure you do something only after checking But rather than this its depends on the condition you are giving because the do while is exit control loop its check the condition at the end of the loop and the while is entry control that's check the condition at the starting of the loop...
15th Nov 2019, 6:58 AM
⚔ Cruzie ⚔
⚔ Cruzie ⚔ - avatar
- 1
which is better a hammer or a saw? just use the right tool for the right job.
12th Nov 2019, 11:03 PM
Logomonic Learning
Logomonic Learning - avatar