counterLoop = 1;
while(counterLoop < 10);
{
System.out.println("Hello");
counterLoop = counterLoop + 1;
}
?
What is the problem in the above while loop? How would you correct the problem?
What will be an ideal response?
The placement of the statement-ending semicolon is important when you work with the while statement. In the code, a semicolon is mistakenly placed at the end of the partial statement while(counterLoop < 10). This makes the loop infinite. This loop has an empty body, or a body with no statements in it. The Boolean expression is evaluated; and because it is true, the loop body is entered. Because the loop body is empty, no action is taken, and the Boolean expression is evaluated again. Nothing has changed, so it is still true, the empty body is entered, and the infinite loop continues.
You might also like to view...
What is the maximum number of edges in a directed graph on n vertices? Explain how you arrived at your solution.
What will be an ideal response?
What value is contained in the floating point variable depth after the following statements are executed
``` depth = 2.4; depth = 20 – depth * 4; depth = depth / 5; ```
The ____ captures the network traffic from the Ethernet connection.?
A. ?capture driver B. ?buffer C. ?decoder D. ?packet analysis
List current FAA regulations for drones. Describe how the following use drones: commercial and media; scientific; military and law enforcement.
What will be an ideal response?