The program allows users to enter integers and identifies and returns the largest one entered. All values greater than or equal to 0 are valid; users enter a -1 to end the data input. A do-while-loop is a good choice for the solution. For- and while-loops are test-at-the-top loops, requiring the variables in the test to be initialized before entering the loop and performing the test.
Alternatively, a do-while-loop is a test at the bottom loop, meaning the loop body runs before the loop test occurs. So, the program can often initialize the variables in the loop test in the loop body. If we again name the variable used for user input number, we can prompt the user for input and enter the numbers in the loop body. The program still initializes number before using it in the loop test.
As with the previous solution, we must compare number and max inside the loop and update max whenever number is greater.