Home > Back-end > The while loop can completely replace the do while loop? So, where is the meaning of the do while lo
The while loop can completely replace the do while loop? So, where is the meaning of the do while lo
Time:09-25
While 1: # the statement If exit the loop condition: Break
The above statement is not under any circumstances can replace the do while loop?
CodePudding user response:
While this cycle is doing before, to determine a condition Do while is finished after the cycle, whether a condition That is to say the do while anyway once the content And while not necessarily
If from the structure, both can through writing and logical processing, entirely replace each other How to choose, the key is to see what kind of writing more helpful in their understanding of this logic, which more convenient method in the current situation
CodePudding user response:
Examples of such as your main building, the reverse is also true
Do { If exit the loop condition: break; # the statement } the while (true);
Can completely replace the while
CodePudding user response:
Even for loop, in particular can substitute while writing and do while
Corresponds to the do while form: For (;; ) { # the statement If exit the loop condition: break; }
While more in the form of: For (;; ) { If exit the loop condition: break; # the statement }
CodePudding user response:
Do will perform at least once while While probably won't be executed at a time