Python modify if i would range () cycle impact

Copyright: As this article have questions, please contact the author micro letter kxymxzs, welcome harassment! https://blog.csdn.net/MG_ApinG/article/details/89531884

a = 2
for i in range(10):
    print('原来的i {0}'.format(i))
    if a < 3:
        i -= 1
        print('后面的i {0}'.format(i))

原来的i 0
后面的i -1
原来的i 1
后面的i 0
原来的i 2
后面的i 1
原来的i 3
后面的i 2
原来的i 4
后面的i 3
原来的i 5
后面的i 4
原来的i 6
后面的i 5
原来的i 7
后面的i 6
原来的i 8
后面的i 7
原来的i 9
后面的i 8

When we use the present cycle except + skip and return cycle, the cycle parameters may be modified i- = 1, but using range () does not produce modified for cycle i the cycle, into use for i <n: such cycles can be.

If you have questions, please contact me, welcome harassment:

                                                             

Guess you like

Origin blog.csdn.net/MG_ApinG/article/details/89531884