What is the purpose of a do-while loop?

前端 未结 5 2080
说谎
说谎 2021-01-17 08:59

I know what do does, and how it cooperates with the while loop, but won\'t a while loop code be the same, whether or not the do is there?

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 09:43

    Use do-while() construct when you have to get your task executed at least once even if condition fails. Use while() when you your task to be executed only on certain condition success.

提交回复
热议问题