• 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

Tough time with nested for loops

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,
I am having a tough time with nested for loops. For example, the following:
What will be printed?
outer: for( int i_=1; i<5 ;i++)
{ inner : for ( j= 1;j<5;j++)
{ if (j==3) continue outer:
System.out.prinltn("i= " + i ",j = " + j)
}
}

Is there an easy way to figure out this apart from "a pen and a paper" method ?
Any other loops related questions in this thread will be helpful.
- rexian
------------------

If u are tired of it then get done with it

 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The pen and paper method works for me. You just have to follow each iteration of the loop and output it remembering what 'continue' does. A little tedious, but easy to do.
 
reply
    Bookmark Topic Watch Topic
  • New Topic