Apr-17-2019, 03:14 AM
Hi Gents,
I could not do Step 5 in this Skipping loop exercise, for step 5, where do I put the codes thanks.
1)Start a new program with a statement creating a loop that iterates three times
for i in range( 1, 4 ) :
2)Next, add an indented statement creating a “nested” inner loop that also iterates three times
for j in range( 1, 4 ) :
3)Now, add a further-indented statement in the inner loop to display the counter
numbers (of both the outer loop and the inner loop) on each iteration of the inner loop
print( ‘Running i=’ + i + ‘ j=’ + j )
4)Save then run this program – to see the counter values on each loop iteration
5)Insert a break statement at the start of the inner loop to break from that loop – then run the
program again
if i == 2 and j == 1 :
print( ‘Breaks inner loop at i=2 j=1’ )
break
Code above in python tags
I could not do Step 5 in this Skipping loop exercise, for step 5, where do I put the codes thanks.
1)Start a new program with a statement creating a loop that iterates three times
for i in range( 1, 4 ) :
2)Next, add an indented statement creating a “nested” inner loop that also iterates three times
for j in range( 1, 4 ) :
3)Now, add a further-indented statement in the inner loop to display the counter
numbers (of both the outer loop and the inner loop) on each iteration of the inner loop
print( ‘Running i=’ + i + ‘ j=’ + j )
4)Save then run this program – to see the counter values on each loop iteration
5)Insert a break statement at the start of the inner loop to break from that loop – then run the
program again
if i == 2 and j == 1 :
print( ‘Breaks inner loop at i=2 j=1’ )
break
Code above in python tags
for i in range( 1, 4 ) : for j in range( 1, 4 ) : print( ‘Running i=’ + i + ‘ j=’ + j ) if i == 2 and j == 1 : print( ‘Breaks inner loop at i=2 j=1’ ) break