148k views
1 vote
Which of the following while loops would continue to loop as long as num has values between the range of 3-12, exclusive?

a) while num > 3 and num < 12:
b) while 3 < num < 12:
c) while num >= 3 and num < 12:
d) while 3 <= num <= 11:

User Forivin
by
8.1k points

1 Answer

2 votes

Final answer:

The while loop that will keep running as long as 'num' is between 3 and 12, exclusive, is 'b) while 3 < num < 12:'. This condition ensures that the loop operates within the desired range without including the boundary values.

Step-by-step explanation:

The correct while loop that would continue to loop as long as num has values between the range of 3-12, exclusive, is b) while 3 < num < 12: This statement will evaluate to true as long as num is greater than 3 and less than 12, which is what we want for the loop to continue running only when num is in that range.

Option a) while num > 3 and num < 12: would also evaluate correctly, but it is less clean than the simpler syntax provided in option b). Option c) while num >= 3 and num < 12: includes the number 3 which is outside of the exclusive range. Option d) while 3 <= num <= 11: incorrectly restricts the upper bound to 11, excluding the number 12 which should be considered.

User Mahmoud Adel
by
8.0k points

No related questions found