+ 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.
23 odpowiedzi
+ 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
+ 4
https://code.sololearn.com/cVbstyuLlINs
In the above code why the count value 8 is not going to print ?
+ 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
+ 3
Change to count<=8.
Loop exiting when count =8, hence will not repeat.
+ 3
They both perform different task so we can't say which one is better
+ 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
+ 2
While loop because Python does not have do while loop.
+ 2
Do while is best but for long program
For short problem while lope is best💻🖥️
+ 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.
+ 2
I prefer While loop as it checks the condition first and then goes into the loop.
+ 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 .
+ 1
You need to count=8
Or count<9
+ 1
As do while is prefer when you want to run the program at least once .but while much easygoing
+ 1
while is semple
0
while is an entry controlled loop, *while* do-while is an exit controlled loop structure.
0
Do you get to Know difference between do while and while
0
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...
- 1
which is better a hammer or a saw? just use the right tool for the right job.