Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Sam Johnson   on Jun 24 In Java Category.

  
Question Answered By: Scarlett Hughes   on Jun 24

I see a for  loop like this:

for (init_statement; bound_checking; step_statement) {}

So, normally you would do this:

for (int i = 0; i < 10; i++)

But, if i is already defined, then you don't have to put it in the for loop:

int i = 3;
for ( ; i< 10; i++)

And let's say your loop ends only on specific conditions:

int i = 3;
for ( ; ; i++) {
...
if (condition1 && condition2)
break;
}

Now let's say your step is defined somewhere in the loop:

int i = 3;
for ( ; ; ) {
...
if (condition1 && condition2)
break;
i += someNumber;
}

Once you get to this point, for (;;) is the same as do .. while(true), which is
the same as while(true).

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on for(;;) Or get search suggestion and latest updates.


Tagged: