Please how does this code work(the increment and the while loop) | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Please how does this code work(the increment and the while loop)

Csharp while loop and increment https://code.sololearn.com/c1qSbeUKA7Kb/?ref=app

25th Apr 2021, 12:35 PM
Obinna Anosike
Obinna Anosike - avatar
2 Antworten
+ 1
Obinna Anosike (Codrrs) Need Storms­čŞĆ­čŞĆ­čŞĆ As num++ is post increment so it will first assign then increment by 1 So here while (num++ < 6) { } for num = 0, num++ < 6 //true but num is incremented by 1 so it will print 1 for num = 1, num++ < 6 //true and print 2 for num = 2, num++ < 6 //true and print 3 ------- for num = 5, num++ < 6 //true and print 6 for num = 6, n++ < 6 // 6 < 6 //false but num will be increment by 1 so num will be 7 but in 2nd print statement there is ++num so it will print 8 Now you have initialised num with 5 so 5 and 7 will be print
25th Apr 2021, 12:51 PM
A͢J
A͢J - avatar
25th Apr 2021, 1:29 PM
Obinna Anosike
Obinna Anosike - avatar