What is the difference between while and do while statements | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What is the difference between while and do while statements

15th Sep 2019, 12:22 PM
Kande Likhitha
Kande Likhitha - avatar
4 Answers
25th Oct 2019, 5:44 PM
Rohitman
Rohitman - avatar
+ 5
"while" is pre - test, it check the condition first before executing the inside code , while the "do while" is post - test that it execute the code first then check the condition.
15th Sep 2019, 12:34 PM
John Nehry C. Dedoro
John Nehry C. Dedoro - avatar
+ 3
while loop first check the condition then execute the code inside the loop do while first execute the code inside the loop then check the condition So do while execute once even the condition is false
15th Sep 2019, 1:47 PM
Chinmay Swarup Chiranjeevi
+ 2
x = 1 example: while(x > 2){ display "hello" } output : (no ouput) because the condition is already false do { dipslay "hello" } while(x > 2) output : hello
15th Sep 2019, 12:38 PM
John Nehry C. Dedoro
John Nehry C. Dedoro - avatar