For the difference between the loop and whlie

  • for loop
    format: for (initial values of variables; loop end condition; loop) {
    ...
    }
    condition determination mode: for loop after performing the end of the loop body condition is again, if the condition is still satisfied, the continued execution cycle, on the contrary, the ends cycle.
    Advantages and disadvantages: variable values and conditions are at the beginning of the cycle position, the code concise, appropriate in the circumstances cycles known.

  • while loop
    form: while (determination condition) {
    loop body
    }
    condition determination mode: while entering the loop when the loop condition is satisfied, when the condition is not satisfied, after executing the loop body after all the statements out, rather than immediately out of the loop.
    Advantages and disadvantages: loop inside, there is no clear and concise for loop, but can be used for cycles unknown.

Released seven original articles · won praise 2 · Views 269

Guess you like

Origin blog.csdn.net/sy140823/article/details/104325493