What does do while loop do and it is different from for loop ? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 4

What does do while loop do and it is different from for loop ?

still confused

26th Nov 2018, 1:24 AM
N Sin
N Sin - avatar
6 ответов
+ 1
In for loop , first of all condition is checked then it runs but in case of do while it runs first after then it checks the condition. It means for loop runs when condition is true whereas do while runs although the condition is wrong and then check. So for wrong condition , in for loop there would be no iteration but do while executes it one time whether it is wrong.
30th Nov 2018, 3:58 AM
Jkilop
+ 7
for loop checks the condition first and then goes inside the loop whereas do while is executed once and then checks the condition
26th Nov 2018, 1:18 PM
Mehak Jain
+ 4
"for" loop verifies the condition before the execition of the cycle. "do while" verifies the condition after that, so the cycle is executed at least once.
26th Nov 2018, 1:49 AM
Микола Федосєєв
Микола Федосєєв - avatar
+ 4
Thank you for your help
28th Nov 2018, 5:40 PM
N Sin
N Sin - avatar
+ 4
All loops do repetitive tasks, all can replace each other in most of cases, difference is small. while - > use when you don't know how many repetition will be required do while - > use when at least one repetition is required even if condition is false for - > use when you know how many repetition are required for each - > same as for but easy / quicker to write
3rd Dec 2018, 1:39 PM
🇵🇰 Danish Khan 🇵🇰
🇵🇰 Danish Khan 🇵🇰 - avatar
+ 1
In for we know that how many times the loop should repeat but in while we don't know that how many time loop should repeat
5th Dec 2018, 11:15 AM
Muqadas