75.7k views
1 vote
Consider the following code:

REPEAT UNTIL (x mod 2 = 1) { x ← x + 3 }
Assume that x is initially 6. How many times will the loop iterate?
Option 1: 2
Option 2: 3
Option 3: 4
Option 4: 5

1 Answer

5 votes

Final answer:

The loop will iterate 3 times.

Step-by-step explanation:

The code in question contains a repeat-until loop that continues until the condition (x mod 2 = 1) is met. The loop increments the value of x by 3 each time it iterates. Assuming x is initially 6, let's analyze how many times the loop will iterate.



Starting at 6, the first iteration will increment x to 9. The second iteration will increment x to 12. The third iteration will increment x to 15. At this point, the loop will terminate because (15 mod 2 = 1). Therefore, the loop will iterate 3 times.

User Technicolor
by
8.6k points