Multiple choice

How many times will the body of the following loop execute? nt m = 10,n = 7; while(m%n>0) {… m = m+1; n = n + 2; …. }

  1. 4

  2. 3

  3. 0

  4. Infinite

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The loop executes as long as m % n > 0. Initially, 10 % 7 = 3 (True). After iteration 1, m=11, n=9, and 11 % 9 = 2 (True). After iteration 2, m=12, n=11, and 12 % 11 = 1 (True). After iteration 3, m=13, n=13, and 13 % 13 = 0 (False), so the loop terminates after 3 executions.