Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

For Loop only two things included C++

Tags:

c++

loops

Lets say I have

int j = 23;
for (j < 20; j++) {
    //do stuff
}

I know it seems stupid in this context but is this possible? Or do you have to do

int j = 23;
for (j; j < 20; j++) {
    //do stuff
}
like image 765
JDN Avatar asked Nov 16 '25 20:11

JDN


1 Answers

You'd typically use an empty initializer:

for (; j < 20; ++j)

Granted, it's just an example, but if j is initialized 23, the for loop will never execute at all.

like image 79
Adam Liss Avatar answered Nov 19 '25 09:11

Adam Liss