**MEDAL + FAN** Please check my Java Programming answers. If I answered a question incorrectly, please show me how to get the correct answer (it's fine if you don't, however). I'd like to learn how to do it on my own.
The term associated with loops inside of loops, is called a nested loop. You can have a nested for loop, nested while loop, nested do-while loop ect.
For question no. 3: the question is: there is a nested for loop inside a for loop- the outside for loop has 4 iterations (iteration means to cycle- so the outside loop cycles through 4 times.) and the nested for loop has 3 iterations --How many times does the Initializer run in the nested for loop: So, I'll start with the syntax of a for loop- for(<initializer>; <boolean>; <update-expression>) { } In a normal non-nested for-loop, the initializer will initialize once total, and it does so first before anything else. but if you had a for loop in a for loop- the initializer in the inner for loop will execute as many times as the outer for loop executes. For Example: int accumulator = 0; for(int count = 1; count <= 10; count++) { System.out.println("After the program runs, this message will show 10 times"); for(int innerLoop = 1; innerLoop <= 5; innerLoop++) { accumulator = accumulator + 1; } } System.out.println("This program has a total of " + accumulator + " iterations."); This is an example of a nested for loop- the inner loop will initialize variable innerLoop to equal 1, then run through 5 iterations before finishing, then the outer for loop will run again. This 2nd time through, the initializer for the inner loop will initialize again- setting innerLoop back to 1, so it can cycle through another 5 iterations. I'm assuming you have some knowledge of for loops already.. if you don't understand something- let me know. Also, a trick for finding out the total number of iterations in a nested for loop, is to multiply the number of iterations of each loop. So if an outer loop has 10 iterations, and the inner loop has 5 iterations-- total number of iterations = 10 * 5
@woodrow73 Thank you for your help :)
Join our real-time social learning platform and learn together with your friends!