Java Reference
In-Depth Information
The outer loop counts up from n=1 to n=12 . For every iteration of the outer loop, the inner
loop counts up from m=1 to m=12 . This means that it starts in the first iteration with n =
1 and m = 1 , producing the following output that is logged to the console:
<< 1 multiplied by 1 is 1
In the next iteration, we are still inside the inner loop, so n remains as 1, but m is incremen-
ted to 2, giving:
<< 1 multiplied by 2 is 2
m continues to increase until it reaches 12. After this, we leave the inner loop and return to
the outer loop, where n increases to 2. We then re-enter the inner loop and m is reset back
to 1 and begins counting up to 12 again. This continues until the last iteration produces the
<< 12 multiplied by 12 is 144
Looping over Arrays
A for loop can be used to iterate over each value in an array. If we take our pizzas array
example from earlier, we can create a for loop that outputs each item in the array to the
console using the following loop:
for(var i=0, max=pizzas.length; i < max; i++){
<< "Chicken & Bacon"
<< "Chicken and Mushroom"
<< ""Ham & Mushroom""
<< "Mushroom"
<< "Spicy Beef"
<< "Veggie Deluxe"
Search WWH ::

Custom Search