How "break" works

Jun 7, 2011 at 7:51am
Hi,

My doubt is the funcionality of the "break".

It is used mainly for switch control structure, but in other cases, a lot of people use it into a function and in while loops, with an if structure.

What does it really do?

Thanks a lot.
Regards,
Maria.
Jun 7, 2011 at 7:55am
break is used to exit a switch statement or a loop (for, while, do/while statements).
Jun 7, 2011 at 10:38am
Thanks,
but what happens if you have a while inside another, it exits only one level? Or in case you have an if-else clause inside a while loop?
Jun 7, 2011 at 10:42am
break does not affect if/else, nor they it.
break will skip you out of only one level of loop.
Jun 7, 2011 at 10:44am
You can't use break to exit from a loop if you use it in a switch statement either, since it will just exit from the switch statement.
Jun 7, 2011 at 1:41pm
Thanks a lot :)

Next I have an example where the break is used into a while working into a switch.

http://ideone.com/5ERSd
Jun 7, 2011 at 1:54pm
The declaration of i isn't quite right in that example.
Topic archived. No new replies allowed.