Difference between “while” loop and “do while” loop

前端 未结 16 1102
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 06:44

What is the difference between while loop and do while loop. I used to think both are completely same.Then I came across following piece of code:

do {
                


        
16条回答
  •  一向
    一向 (楼主)
    2020-12-13 07:25

    While:

    1. entry control loop

    2. condition is checked before loop execution

    3. never execute loop if condition is false

    4. there is no semicolon at the end of while statement

    Do-while:

    1. exit control loop

    2. condition is checked at the end of loop

    3. executes false condition at least once since condition is checked later

    4. there is semicolon at the end of while statement.

提交回复
热议问题