newcomer to Java.. how to end a loop?

hi, what is the difference between:return;break; andcontinue;?
[104 byte] By [Inbala] at [2007-10-3 2:47:45]
# 1
Return: ends the current method. If a return value is required, the Return statement must give it.break: jumps out of the current loopcontinue: immediately breaks the current loop, and continues with the next iteration (if there is one).
Mongera at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 2

> hi,

> what is the difference between:

> return;

> break; and

> continue;

> ?

In the context of from within a loop, return returns control to the calling code, break gives control to the line following the loop, and continue gives control to the line that starts the loop (skipping the rest of the code in the current iteration).

Hope that helped

Lee

tsitha at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 3
> hi, > what is the difference between:> return;> break; and> continue;> ?return completes the methodbreak terminates the loopcontinue skips the current iteration of the loop
el_doradoa at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 4
A moment ago there were no replies and now
el_doradoa at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 5
there are 5
tsitha at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 6
thanks so much everyone
Inbala at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 7

It should also be noted (if it hasnt) that you can LABEL loops

and break out of specific loops by name.

http://www.devx.com/tips/Tip/31853

X:

for (int i = 0; i < x; i++) {

...

Y:

for (int j = 0; j < y; j++) {

...

Z:

for (int k = 0; k < z; k++) {

...

if (some_condition) {

break Y;

}

}

}

...

*

}

TuringPesta at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...
# 8
Labeled loops?!!?Smithers, release the hounds!!
bckrispia at 2007-7-14 20:36:32 > top of Java-index,Java Essentials,New To Java...