0

C# error in continue and break question 1

Heres the question: for(int x = 1; x <= 8; x++){ If(x > 5) break; } what will x be? (Answer is 5????) If x = 5 X is not larger or small than 5 because x is five Therefore when x is five it should not be breaking the loop

3rd Dec 2019, 12:31 AM
Flamingo Sexylegs
Flamingo Sexylegs - avatar
2 Respuestas
+ 1
You are right. When x is 5 it does not break the loop because 5 > 5 returns false. x gets 6 and now 6 > 5 returns true. So the loop breaks when x gets 6.
3rd Dec 2019, 12:39 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
the issue is that people learning c# may use those operators incorrectly if the place they are learning it from has them wrong
6th Dec 2019, 5:13 PM
Flamingo Sexylegs
Flamingo Sexylegs - avatar