Checkpoint 5.2.2.
We call each time we execute the body of the loop an ________.
while
statement
while
statement. Here is the program for our table of squares and cubes using a while
statement that produces the same output. Step through this program with codelens so you can see the repetition in action.while
statement as if it were English. It means, “While n
is less than or equal to five, display the value of n
, n
squared, and n
cubed; then increase the value of n
by 1. When you get to 6 (which is not <= 5), exit the while
statement and display the line of dashes.”while
statement:True
or False
.while
statement and continue execution at the next statement.while
loop.x
and y
when this while
loop finishes executing?x = 2
y = 5
while (y > 2 and x < y):
x = x + 1
y = y - 1
x
is 2; y
is 5x
and y
at first, but they changed by the time the loop finished executing. Try again.x
is 5; y
is 2while
loop will finish executing before x
and y
reach these values. Try again.x
is 4; y
is 3x
equals 4 and y
equals 3 because at that point, x
is not less than y
.x
is 4; y
is 2x
and y
, it is impossible for y
to be 2 when x
is 4. Try again.print
statement so you can see the values of x
and y
at each iteration. You might also want to use codelens to see the values of x
and y
step by step.