gudii9
asked on
nested loop race track
Hi,
I am reading about nested loop here
http://study.com/academy/lesson/nested-for-loops-in-java.html
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
}
}
what it means by race track within a race track not able to visualize this image or picture
what it means by each lap on main oval and veer to another track inside original track??
please advise
I am reading about nested loop here
http://study.com/academy/lesson/nested-for-loops-in-java.html
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
}
}
Think of a nested loop as a race track within a race track. When you begin each lap on the main oval, you veer into another track inside the original (the nested track/loop). You may go around any number of times within the smaller track before looping around the main one. Then it starts over again until you've done the required number of laps on the main track. In all, you may go around a thousand times, or many more!
what it means by race track within a race track not able to visualize this image or picture
what it means by each lap on main oval and veer to another track inside original track??
please advise
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I think that what this is conveying is that if we are on loop 5 for I, then the visualization would be "we are going on the 5th outer lap for I, but before we do that, we need to do 5 inner laps for J"not completely any practical example on this?
I hope this helps you visualize it.
ASKER
i saw some wheel inside wheel images here
https://www.google.com/search?q=wheel+inside+a+wheel&rlz=1C1GGRV_enUS765US765&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi7r9rIxNzWAhXE4iYKHU-tCT4Q_AUICigB&biw=1279&bih=613
nothing is close right?
https://www.google.com/search?q=wheel+inside+a+wheel&rlz=1C1GGRV_enUS765US765&source=lnms&tbm=isch&sa=X&ved=0ahUKEwi7r9rIxNzWAhXE4iYKHU-tCT4Q_AUICigB&biw=1279&bih=613
nothing is close right?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Do you have a wristwatch? With hands? With a second hand ?perfect example. thank you
OK, so how do the minutes relate to the seconds ?
ASKER
hours minutes and seconds are 3 hands of clock like 3 nested for loops
Right.
So whilst the clock is hard-wired to 60 (for minutes and seconds), loops can be any number inside any other number.
So whilst the clock is hard-wired to 60 (for minutes and seconds), loops can be any number inside any other number.
loops inside loops in solar system
inner planets closest to the sun moves faster than outer planets
inner planets closest to the sun moves faster than outer planets
But the planets are all moving at the same time, which is not the case with loops.
this is the case with nested loops. An outer planet is the outer loop, an inner planet is the inner loop. For one full loop of the outer planet around the sun, an inner planet (inner loop) can make 2,3 and much more loops.
Yes, I understand all that.
But planets are not a good analogy as they are all moving at the same time it gives a possible false impression that loops do too. With a clock, the movements are co reliant. If Neptune disappeared it would have no effect on Mercury.
But planets are not a good analogy as they are all moving at the same time it gives a possible false impression that loops do too. With a clock, the movements are co reliant. If Neptune disappeared it would have no effect on Mercury.
ASKER