Live Loop

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

count = count + 1;

It increases count by one.

If this is not clear, remember the two steps of an assignment statement: first evaluate the expression on the right of the equal sign, second put the value in whatever variable is on the left. Say that count is 5. When the above statement executes, first the expression is evaluated, resulting in 6. Second the 6 is put in count.

Live Loop

while loop

 

Here is a simulation (using JavaScript) of the loop. Click on the "run program" button to see the output of the loop. Examine the flowchart to see how the looping has been done.





If you look at the source for this page using your browser's "View Source" menu item, you will see the JavaScript that is responsible for the above. JavaScript is similar to Java, but has some big differences, so be careful not to get confused.


 

QUESTION 3:

If the "3" where changed to a "10" how many times would the program loop?