Could someone explain, what is actually happening there? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Could someone explain, what is actually happening there?

https://code.sololearn.com/cjP3UwQ5p8Ih/?ref=app

30th Sep 2021, 4:37 PM
ahsan rzingpa
ahsan rzingpa - avatar
2 Answers
+ 7
Your code runs an infinite loop. It happens because you increment <num> by one, until <num> becomes 6, where an `if` block decremented <num> to 5. This happens over and over.
30th Sep 2021, 4:44 PM
Ipang
+ 4
Its quite simple: once num reaches 5 it gets increased up to six first then as it is already six if(num==6) is true then because of num= num-1; num gets decreased back to 5 and loop repeats itself for infinity....
30th Sep 2021, 4:42 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar