You are on page 1of 4

1. What are the differences between a while loop and a do-while loop?

Convert the following


while loop into a do-while loop.
The different is while loop, the user input checked first, and do-while loop test after the
syntax run.

2. Do the following two loops result in the same value in sum?


The Value is the same, based on the syntax that run above the output is the same.

3. What does the following statement do?

for( ; ; ){

do something;

The statement run the syntax we type but it will loop the code forever, or programmer said that
the syntax id infinite looping. The pic ture below show infinite looping.
4. Can you always convert a while loop into a for loop? Convert the following while loop into a
for loop.

The answer is yes, we can change the syntax from while loop to for loop, they have same
characteristic but different appearance.

5. After the continue statement is executed in the following loop, which statement is
executed? Show the output.
The statement that execute is statement System.out.println(i*j);
The output is:

You might also like