...
|
|
You can often use for-loops to make code easier to read. The following code with nested for-loops prints...
|
|
You will find out that the control enters the first for loop and the value of the variable number
is initialized as 0. The first print statement is printed, and then control enters the second for loop, where the value of the variable another_number
is initialized to 0
. The first print statement in the second for loop is printed once.
Now, the control returns to the inner for loop once again and the value of another_number
is again initialized to the next integer followed by printing the statement inside the print()
function.
The aforementioned process continues until the control has traversed through the end of the range()
function, which is 5 in this case, and then the control returns back to the outermost loop, initializes the variable number
to the next integer, prints the statement inside the print()
function, visits the inner loop and then repeats all of the above steps until the range()
function is traversed.
This journey of the control traveling from the outermost loop, traversing of the inner loop and then back again to the outer for loop continues until the control has covered the entire range, which is 3 times in your case.