Resolved Do variables retain their adjusted values after a loop?

haychu

New member
Joined
Feb 12, 2022
Messages
2
Programming Experience
Beginner
For example

C#:
int g = 1

while (g <= 10)
{
    Console.WriteLine(g);
    g++;
}


Will the 'g' variable stay 10 for any code past the while loop or will it return to its original value of 1? Curious about bool/string/etc values as well.
 
Solution
Yes, they retain their values.

No. The value will be 11 past the while loop. Step through the code with a debugger or with pen and paper.
Yes, they retain their values.

No. The value will be 11 past the while loop. Step through the code with a debugger or with pen and paper.
 
Last edited:
Solution
Back
Top Bottom