Wich is the diference between a "while" and a "do while" ?
which is the difference? as in there are options to choose from?
A while statement considers the arguement before executing. Do-while; executes the statement "at least once" before considering the arguement. "While" is thoughtful and will do as it is told; "Do-While" acts without thinking and is impulsive :)
while ->Loop when condition is true and n times,=>entry level condition check.no guarntee to run. do ->enter and check the condition and run n times =>exit level condition check.atleast once loop body executed.
Essentially it is the difference between: while (condition) do_something V/S do_something while (condition) In the first case, the condition gets checked first then "do_something" happens. In the second case, "do_something" happens at least once before the condition gets checked. And thats all there is to it!
"do while" is exit check loop which checks the condition only at the end... so the condition is executed at least once even though the condition is not satisfied. "while" is entry check loop and only if the given condition is true the loop will be executed.
Join our real-time social learning platform and learn together with your friends!