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 finding the value of y when working in C#?

int x = 5, y = 3;

while (x < 20) {

x += 4;

y += x;

}

What are the steps that need to be taken to find the value of y?

1 Answer

Relevance
  • 7 years ago
    Favorite Answer

    Just work through the loop. Make sure you keep track of the value of x and y throughout otherwise it'll quickly go wrong.

    loop 1

    x += 4 = 9

    y += 9 = 12

    loop 2

    x += 4 = 13

    y += 13 = 25

    loop 3

    x += 4 = 17

    y += 17 = 42

    loop 4

    x += 4 = 21

    y += 21 = 63

    x >= 20 so the loop ends. Y = 63 in the end.

Still have questions? Get your answers by asking now.