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
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
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.
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.