60.7k views
0 votes
Which initial value of number would cause an infinite loop? Repeat until (number = 0) { number ← number - 1 } Any positive negative even odd integer.

a. 0
b. 1
c. -1
d. 2

User Raratiru
by
8.6k points

1 Answer

5 votes

Final answer:

The initial value for 'number' that would cause an infinite loop is c. -1, as any negative integer will never satisfy the loop's termination condition, which is for 'number' to equal zero.

Step-by-step explanation:

The student's question asks about a piece of pseudocode and which initial value for the variable number would cause the program to enter an infinite loop. The pseudocode mentioned is a 'Repeat until' loop that continues to execute until the variable 'number' equals 0. Each iteration of the loop decreases 'number' by 1. If the initial value of 'number' is non-positive (i.e., zero or negative), the loop will terminate since the condition 'number equals zero' will eventually be met if 'number' is positive.

However, if 'number' starts as a negative integer, the condition 'number equals zero' will never be met because 'number' will become more negative with each iteration of the loop, moving further away from zero. Therefore, a negative starting value for 'number' would cause an infinite loop. Based on the given options (a. 0, b. 1, c. -1, d. 2), the initial value that would cause an infinite loop is c. -1.

User Chevul Ervin
by
8.2k points