File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Strange behavour in loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Strange behavour in loop" Watch "Strange behavour in loop" New topic

Strange behavour in loop

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
Posts: 192
Please consider this strange behavour:
I have an outer and an inner loop. I want to stop (= break) the
Inner loop on an condition.
But this the loop behaves different when I test for i and in the
Second programm for j in the condition. WHY?
What I want is the result of programm „Test61“: The inner loop
Should end when j is a 1.
But why that behavour in „Test61a“?
Thanks for your answers.

C:\Java\EigeneJavaProgramme>java Test61
Loop; i=0, 0
Loop; i=1, 0
Loop; i=2, 0
Nach Loop; i=3,j= 1

C:\Java\EigeneJavaProgramme>java Test61
Loop; i=0, 0
Loop; i=0, 1
Loop; i=0, 2
Loop; i=2, 0
Loop; i=2, 1
Loop; i=2, 2
Nach Loop; i=3,j= 3
[ November 01, 2002: Message edited by: Dirk Schreckmann ]
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
You are breaking out of the inner loop, but continuing the outer loop. This does just what you say it should do.

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
I agree. Here's the link:
subject: Strange behavour in loop