The code needs to go through 11 inner loop iterations and 3 outer loop iterations to meet the condition of the country being ‘Brazil’ and the capital city being ‘Brasilia’.
The print statement line is only executed the once during the entire script when those conditions are met. At the point of this line being ran, 11 inner loops and 3 outer loops equals 14 in total.
The += 1
in code is the same as saying outer_loop_total = outer_loop_total + 1
. It is a shorthand used for incrementing the variable.
The code -= 1
could be used similarly as a shorthand to decrement a variable by 1.
0
solved How do you get the number in nested loop? [closed]