Are the limits of for loops calculated once or with each loop?

Viewed 5355

Is the limit in the following loop (12332*324234) calculated once or every time the loop runs?

for(int i=0; i<12332*324234;i++)
{
    //Do something!
}
9 Answers

In addition to KLee1's answer, I'm writing the absolutely same thing just a little different to make it more human-readable:

for(int i=0, limit = someFunction(); i<limit ;i++)
{
    //Do something!
}

someFunction() is still only executed once, and the loop's head still fits comfortably in 1 line without confusing your teammates too much. Hopefully! ;-)

BTW, this works in C++, too.

Related