• 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

Nesting

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does java allow unlimited nesting.

For example I had a do while loop. within the do i have an, if, than an else if, and within my else if i have a for loop and the yet another if inside the for. Will I be able to do that
 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure. Better yet, try it out and see what happens!
 
John Kirvan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Kirvan:
Does java allow unlimited nesting.

For example I had a do while loop. within the do i have an, if, than an else if, and within my else if i have a for loop and the yet another if inside the for. Will I be able to do that



So when you say sure your joking i guess
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think he is not joking, but he wants you to prove it to yourself.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whoops, sorry about that...I wasn't even being sarcastic, although I can be! I meant that yeah, Java can definitely handle nesting with loops. Try it out...how would you initialize a matrix of numbers? Say four columns across, and four rows down, and initialize them all to zero, or whatever you want...you'll have to do a bit of nesting...but you can definitely nest as much as you want, actually.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder about the "unlimited" part. I suspect that there is probably some limit. At the very least, this limit is based on the amount of memory in your machine that is available for the compiler. However, even if there is a hard limit, it is probably rather large. In this case, the nesting will work fine. If you are interested in trying to see if there is a limit, I would suggested making A LOT of nested loops and/or if statments. By "a lot", I would guess more than 255. (Typically I would advise to NOT write real code this way, but it can be an interesting exercise to see if there is an actual limit.) Also, you can check out the Java Language Specification to see what it says on this matter.

Layne
 
reply
    Bookmark Topic Watch Topic
  • New Topic