2024/2025
conditional loop - ANSWERSexecutes as long as a particular condition exists.
count-controlled loops - ANSWERSA loop that repeats a specific number of times
What 3 elements must a count-controlled loop have? - ANSWERS-It must initialize a control variable to a
starting value.
-It must test the control variable by comparing it to a maximum value. When the control variable reaches
its maximum value, the loop terminates.
-It must update the control variable during each iteration. This is usually done by incrementing the
variable.
loop header - ANSWERSThe first line of the for loop
initialization expression - ANSWERSit is normally used to initialize a control variable to its starting value.
test expression - ANSWERSThis is a boolean expression that controls the execution of the loop.
update expression - ANSWERSIt executes at the end of each iteration. Typically, this is a statement that
increments the loop's control variable.
counter variable - ANSWERSthis variable keeps a count of the number of iterations
What will the following code segment display?
, for (int count = 0; count < 6; count++)
{
System.out.print(count + count);
System.out.print(" ");
} - ANSWERS0 2 4 6 8 10
What will the following codesegment display?
for (int value = -5; value < 2; value++)
{
System.out.print(value);
System.out.print(" ");
} - ANSWERS-5 -4 -3 -2 -1 0 1
What will the following code segment display?
int x;
for (x = 5; x <= 14; x += 3)
{
System.out.print(x);
System.out.print(" ");
}
System.out.print(x); - ANSWERS5 8 11 14 17
Assuming the variable count has been declared, write a for loop that displays the name "NeilArmstrong"
10 times.
______
{