| Home | Links |
1. Every loop must run once.
True False
2. If you don't move towards the stopping condition, the loop never ends.
3. The Boolean expression in a loop is the same as the stopping condition.
4. If the Boolean expression is true, then the loop keeps running.
5. All variables that are used after the loop must be declared outside the loop.
6. In Java, there are three types of loop constructs: while, for while, do while.
7. A loop is a code that repeats.
8. Which of the choices is NOT a part of the four elements of a loop?
Steps to repeat Changing the variable Test the stopping condition Initialize stopping variable
9. What will the following code print on the screen?
for (double x = 15; x < 16; x ++) { System.out.print (x + " "); }
for (double x = 15; x < 16; x ++) {
System.out.print (x + " ");
}
15 16 15 15.0 16
10. What is wrong with the following code?
for (int x = 0; x <= 20; x +=3); { System.out.print (x + " "); }
for (int x = 0; x <= 20; x +=3); {
Semi-colons (;) in the brackets should be commas (,) Instead of "print", it should be "println" The Boolean expression should be =< There should be no semi-colon at the end of the "for" statement
11. Which one of the statments is true for the code below?
int x = 5; do { System.out.print (x + " "); x += 5; } while (x <= 50); System.out.println ("Done");
int x = 5; do {
System.out.print (x + " "); x += 5;
} while (x <= 50); System.out.println ("Done");
This loop prints 10 different numbers on the screen The last number it prints is 45 The loop goes up by 4 each time "Done" is printed after each number
12. What kind of loop is this?
int x = 5; while (x <= 10) { System.out.print (x + " "); x ++; }
int x = 5; while (x <= 10) {
System.out.print (x + " "); x ++;
int while do while while and do while