SCRIPTING-AND-PROGRAMMING-FOUNDATIONS practice question 18 of 25

Which snippet represents the loop condition expression in the given code?

Full set: 137 questions
Answer options
A: Integer f = 1
B: Put f to output
C: F < 27 Correct answer
D: F = f + 2
Correct Answer:
C. F < 27
Explanation

A loop condition is a boolean expression that is evaluated before each iteration of a loop. The result of this evaluation (true or false) determines whether the loop's body will execute. In a typical while or for loop structure, the expression f < 27 serves this purpose. The loop continues to execute as long as the variable f is less than 27; it terminates once this condition becomes false.

Why Incorrect

A. Integer f = 1 is the initialization of the loop control variable, which occurs once before the loop begins.
B. Put f to output is a statement within the body of the loop that executes during each iteration.
D. f = f + 2 is the update statement (or increment/step), which modifies the loop control variable, typically at the end of each iteration.

References

1. MIT OpenCourseWare. (2016). 6.0001 Introduction to Computer Science and Programming in Python. Fall 2016. Lecture 3, Section: "While Loops". The lecture defines the loop condition as the expression tested each time through the loop.

2. Oracle. (2023). The Java™ Tutorials: The while and do-while Statements. The documentation explicitly defines the expression part of while (expression) as the condition that must evaluate to true for the loop to continue.

3. Kernighan, B. W., & Ritchie, D. M. (1988). The C Programming Language (2nd ed.). Prentice Hall. Chapter 3, Section 3.5, "Loops—While and For," describes the conditional expression that controls the loop.

Scroll to Top