课程: Java Essential Training: Syntax and Structure

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Do while loop

Do while loop

- [Instructor] A do while loop is very similar to a while loop, except it checks the condition after execution as opposed to before. This means that a do while loop executes at least once. Note that do while loops are rarely used as the while loop will usually meet your needs. However, it's still good to know about do while and how it works. In this problem, we're asked to write a program that allows a user to enter two numbers and calculate the sum. The program should repeat these actions until the user indicates they are done. To create a do while loop, we'll write the word do, followed by a set of curly braces. Notice, there's no condition here because the do while loop doesn't check the condition until after the loop has been run one time. All statements that we want to execute go inside of the curly braces and at the end of the loop, we add the word while and a condition will go inside of that set of…

内容