Pleaze why 6 is printed in this code ???? 6<6;??? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Pleaze why 6 is printed in this code ???? 6<6;???

problem https://code.sololearn.com/cszQ0L11vukc/?ref=app

24th Jun 2018, 11:09 AM
Anas Sanba
12 Answers
+ 2
It is because when the code starts executing first the num is checked for the previous value but it prints the next value. So in the last iteration the num will be checked for 5<6 which is true & because of post increment it increments later which becomes 6 & since the condition is true the control comes inside while & Prints 6. ● If you will observe it starts from 1 not from 0 even when num is set to 0 so it is obvious it will give one extended value bacause it is starting from one extended value so it will end with one extended value also. ------------------------------------------------- I hope it helps.
24th Jun 2018, 12:26 PM
Rahul Sahani
Rahul Sahani - avatar
+ 2
you're welcome
24th Jun 2018, 12:55 PM
Rahul Sahani
Rahul Sahani - avatar
+ 1
oh thx rahul finally i get it ^^ thank you so much
24th Jun 2018, 12:29 PM
Anas Sanba
0
try this while(num < 6){ Console.WriteLine(num); num++; } the mistake you made is that you didn't make num increasing so it would be an infinite loop
24th Jun 2018, 11:19 AM
TheCoder04
0
really? 😒
24th Jun 2018, 11:21 AM
Anas Sanba
0
yep
24th Jun 2018, 11:21 AM
TheCoder04
0
I am asking why 6 is printed
24th Jun 2018, 11:22 AM
Anas Sanba
24th Jun 2018, 11:24 AM
RainStorm
RainStorm - avatar
0
I have no idea.
24th Jun 2018, 11:25 AM
RainStorm
RainStorm - avatar
0
xD
24th Jun 2018, 11:31 AM
Anas Sanba
0
oh in that case i dont know since c# is not my "native" programming language
24th Jun 2018, 11:44 AM
TheCoder04
0
ok
24th Jun 2018, 11:46 AM
Anas Sanba