0

For(;;) logic with example

I can't understand how does it work in programming logic. Can anyone explain it with an example? I want to know please help.

4th Sep 2019, 3:04 PM
Krishnanshu Dey
Krishnanshu Dey - avatar
6 ответов
+ 4
A for loop has a place to initialize variables, a place for an ending condition and a place to change variables basically. for(int i=1; i<=10; ++i) { // Do stuff } i increases up to 11, and then the loop stops, because the condition is not true anymore. f(;;) just means that you leave all slots empty. You create no values, don't change them - and, most important, you have no condition, so the loop doesn't know when to stop. Which means it'll just run forever (or until there's a break).
4th Sep 2019, 3:23 PM
HonFu
HonFu - avatar
+ 2
Exactly.
4th Sep 2019, 3:37 PM
HonFu
HonFu - avatar
0
Do you mean for(;;) instead of if?
4th Sep 2019, 3:06 PM
HonFu
HonFu - avatar
0
Yes sorry for mistake it will for(;;)
4th Sep 2019, 3:07 PM
Krishnanshu Dey
Krishnanshu Dey - avatar
0
Oooooo you mean it will go for infinite loop right.
4th Sep 2019, 3:30 PM
Krishnanshu Dey
Krishnanshu Dey - avatar
0
Thanks you got it.
4th Sep 2019, 3:38 PM
Krishnanshu Dey
Krishnanshu Dey - avatar