Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Need help with loops in programming in particular C#?

How many times will the body of the while loop be executed if x has the value 11 at

the start of the loop?

while (x > 0){

System.Console.WriteLine(x);

x -= 2;

}

Which of the following loops terminate? Assume that x has the value 7 at the start of

the loop.

a. while (x < 75) b. while (x > 0)

x += 11; x += 11;

1 Answer

Relevance
  • goober
    Lv 7
    7 years ago
    Favorite Answer

    You should be able to figure this out easily if you understand that

    x -= 2 means x = x -2

    so it executes with x = 11, 9, 7, 5, 3, 1

    Count em up -- 6 times

    x+=11 will eventually get x to 7+7*11 = 84 at which time the loop (x<75) will terminate.

    The loop (x>0) will allow x to grow without bound until an overflow occurs so in practical terms it does not terminate.

Still have questions? Get your answers by asking now.