The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Question about do-while loops?

Hi, please use code tags when posting code, i.e. [code]your code goes here [/code]
j is not always greater than i because j is reset to 1 in every run of the outer loop, but i is incremented in every run of the same loop. So at one point i is 3 and j is 1, that's where the inner loop starts running more than once.

Re: Question about do-while loops?

It looks like this is an experiment in the complications of nested loops. I would suggest taking out the prints that are there and adding new prints that tell you what loop you are in and the values of i and j. This way you can see exactly how the loops are being executed and how the counters are incrementing and effecting them.

Example:
System.out.println("Inner Loop i=" + i + " j=" + j);

Writing code is your job, helping you fix and understand it is mine.

<-- Be sure to thank and REP (Star icon) those who have helped you. They appreciate it!