For Loop Question

Hi I was just wondering what the following does:

for (; j < myVar.length; j++)

I have never seen ; being used as the start of the for loop statement is this correct? The compiler doesnt have any issues with it and Im curious as to what it does, any problems with it etc. i never seen it used like this before.

directxBOBAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSr. Software engineerCommented:
This can be used when the variable j is defined outside the loop:

int j = 0;
for (; j < 10; j++)
  System.out.println(j);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
No need to initialize j if the variable is initialized elsewhere. Otherwise no difference than the usual one
zzynxSr. Software engineerCommented:
That's the same as writing:

for (int j = 0; j < 10; j++)
  System.out.println(j);
zzynxSr. Software engineerCommented:
The generic syntax for a Java for loop is:

for ( {initialization}; {exit condition}; {incrementor} )
     code_block;

You are allowed to leave those blocks empty.
Other example:

        for (int j=0; j < 10;)  // incrementor block left empty
            System.out.println(j++);

zzynxSr. Software engineerCommented:
Thanks for accepting
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.