5.7.1. Loops-WE6-P1ΒΆ
Subgoals for Evaluating a Loop
Diagram which statements go together.
Define and initialize variables
Determine the start condition.
Determine the update condition.
Determine the termination condition.
Determine body that is repeated.
Trace the loop.
For every iteration of the loop, write down the values.
Loops-WE6-P1
- 5 lines of ###
- 3 lines of #####
- 4 lines of ######
- 5 lines of ####
- Compilation error
Q15: What is the output of the following loop?
for (int m = 0; m < 4; m++)
{
for (int n = 5; n >= 0; n--)
{
System.out.print("#");
}
System.out.println();
}
- See diagram for answer A
- See diagram for answer B
- See diagram for answer C
- See diagram for answer D
- See diagram for answer E
Q16: What is the output of the following loop?
for (int m = 0; m < 4; m++)
{
for (int n = 0; n <= m; n++)
{
System.out.print("$");
}
System.out.println();
}

- See diagram for answer A
- See diagram for answer B
- See diagram for answer C
- See diagram for answer D
- See diagram for answer E
Q17: What is the output of the following loop?
for (int m = 1; m < 5; m++)
{
for (int n = 1; n <= m; n++)
{
System.out.print(" ");
}
System.out.println("$");
}

You have attempted of activities on this page