![]() While the first range will hold the list of multipliers corresponding to different rows, on the other hand, the second range will hold the result values. Instead of declaring and initializing a loop counter variable, you declare a variable that is the same type as the base type of the array, followed by a colon, which is then followed. This is equivalent to the foreach loop in languages like C. It starts with the keyword for like a normal for-loop. The for loop iterates through anything that provides an iterator. ![]() Further, we’ll need two ranges in our loop. For-each is another array traversing technique like for loop, while loop, do-while loop introduced in Java5. ![]() Let’s advance our understanding of looping with multiple variables by applying concepts of ranges and the zip operator to generate multiplication tables, where each row shows up in the format: factor x multiplier = resultĪs the factor will remain the same in all the rows, we’ll have to loop through two multiplier and result variables.
0 Comments
Leave a Reply. |