0

How to use nested loops in java

Can someone please help me with an explanation of how to use nested java code. I've tried the w3schools website but I can't quite get a grasp of it. Any help will be much appreciated

7th Mar 2019, 8:57 PM
Null Void
6 Antworten
+ 3
Take a look at this and see if you can understand how it works https://code.sololearn.com/c0eLJJ9S3PgP/?ref=app
8th Mar 2019, 12:14 AM
voidneo
+ 1
The parent loop runs 3 times, starts at zero, and up to two, because two is the biggest integer under 3, and the loop only executes if the counter is smaller than 3 because I decided so. This means that, whatever is inside the parent loop executes 3 times, the nested loop, does two iterations, but since the loop is executed 3 times by its parent, it loops its 2 times, finishes, and the parent executes it again, so it loops 2 more times and so on
8th Mar 2019, 7:02 AM
voidneo
0
What part exactly is giving you trouble? How nested for loops execute step by step?
7th Mar 2019, 11:59 PM
voidneo
0
I'm trying to iterate through the loops.. for loops to be precise
8th Mar 2019, 12:02 AM
Null Void
0
Thanks for the code explanation, but why does the nested for loop runs twice yet its parent only run once. They seem to be written the same way. Sorry for bothering you
8th Mar 2019, 6:13 AM
Null Void
0
Makes sense,, thanks a lot
8th Mar 2019, 8:34 AM
Null Void