• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

for loop and break.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a method like below.
I put a break statement inside inner "for" loop.
I was expecting, when break is executed, it will jump to lblA and next iteration of outer "for" will be started. Contrary, it is going out of outer loop and no result is displayed.
Does anybody has any thoughts on this, please share.
Thanks

[This message has been edited by PGautam (edited March 03, 2000).]
[This message has been edited by PGautam (edited March 03, 2000).]
[This message has been edited by PGautam (edited March 03, 2000).]
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code would look better if you'd indent it... D)
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
PGautam- I see you did indent it when you posted it, but as you see it isn't displayed that way. You need to use the [ code ] and [ /code ] tags (without spaces) before and after you code to make it preserve indentation - read about it here. Also, in the second for statement, there's a ";" and a ")" that need a space between them to prevent them from being interpreted as a smiley ( ).
You can fix these things by editing your post. Go to the little paper-and-pencil icon at the top of your post, and click it. You will be able to change the contents of your post even after it was posted.
For those of you who don't see a paper-and-pencil icon: that's because you didn't register. You're only allowed to edit your own posts, not others. That's a main benefit to registering.
[This message has been edited by Jim Yingst (edited March 03, 2000).]
 
PGautam
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, after inserting [CODE] tags my code looks much better. My question regarding above method is, what i read about "break", it will terminate current loop and goes to outer loop. By running this method, i'm confused, whether break will terminate both loops.
Thanks

[This message has been edited by PGautam (edited March 03, 2000).]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - since you're using a labeled break statement to expilicitly break the outer loop, you will also break out of the inner loop in the process. If what you want is to go to the next iteration of the outer loop rather than quit it completely, then you should use a <code>continue</code>. not a <code>break</code>. Specifically, a labeled continue: <code>continue lblA</code> in place of <code>break lblA</code>.
reply
    Bookmark Topic Watch Topic
  • New Topic