• Post Reply Bookmark Topic Watch Topic
  • New Topic

basic for loops priorities question  RSS feed

 
Filipe Madureira
Ranch Hand
Posts: 44
1
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm new here and this is my first discussion, anyways, i have a problem.

In my programming course we're using "JavaKara" a software that simulates a Ladybug movement in a composite world with Java code.

In a double nested for loop like the one below, it is going to be executed the "kara.turnRight()" code or the inner loop first?

Because when i execute it, it starts by turning right and doesn't execute the inner loop, just only after turning right the first time.



Oh, i think i figured it out. In the nested loop my "j" isn't smaller than "i", but just for the first loop, thus the first inner loop is skipped the first loop, right?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filipe Madureira wrote:
Oh, i think i figured it out. In the nested loop my "j" isn't smaller than "i", but just for the first loop, thus the first inner loop is skipped the first loop, right?


Correct. The first iteration of the outer loop does an inner loop with no iterations.

And thanks, for reporting back with the answer. Have a cow.

Henry
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Filipe Madureira
Ranch Hand
Posts: 44
1
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Filipe Madureira wrote:
Oh, i think i figured it out. In the nested loop my "j" isn't smaller than "i", but just for the first loop, thus the first inner loop is skipped the first loop, right?


Correct. The first iteration of the outer loop does an inner loop with no iterations.

And thanks, for reporting back with the answer. Have a cow.

Henry

Campbell Ritchie wrote:And welcome to the Ranch


Thank you guys!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!