While and do while loops are two types of iteration statements commonly used in programming. They allow a section of code to be repeated multiple times until certain conditions are met. This article will discuss the differences between these two looping methods.
About Difference Between While And Do While
Feature | Difference |
---|---|
Condition Check | While checks the condition before executing, Do While executes first and then check the condition. |
Execution | While only executes when the condition is true, Do While always execute once even if the condition is false. |
Loop Control Variable | In While loop, it must be initialized outside the loop. In Do While loop, it can be declared within the loop. |
Syntax | The syntax of While loop is simpler than Do While loop. |
Usage | While loop is used when number of iteration is not known in advance. Do While loop is used when at least one iteration is necessary. |
Break Statement | Break statement stops the execution of While loop but does not affect the Do While loop. |
— by
Leave a Reply