Python's for loop is essentially implemented by constantly invoking the next () function, for example:
1 #_*_coding:utf-8_*_2 #__author__ = "Csy"3D = ["Coffee Berry Flavor Latte","green tea star Ice Music","Cocoa Shard star Ice Music","Caramel Macchiato","Classic Chocolate","Coffee, Smith .","Hot Milk","Oriental Beauty","Ice Mocha","Cappuccino","American Coffee","Double fruit Juice"]4A = ITER ([0,1,2,3,4,5,6,8,9,10,11])5 whileTrue:6 Try:7x =Next (a)8 Print(D[x])9 exceptstopiteration:Ten Break
Output:
Coffee Berry Flavor Latte
Green Tea star Ice Music
Cocoa Shard Star Ice Music
Caramel Macchiato
Classic Chocolate
Coffee, Smith.
Hot milk
Ice Mocha Card
Cappuccino
American Coffee
Double fruit juice
Equivalent:
1 #_*_coding:utf-8_*_2 #__author__ = "Csy"3D = ["Coffee Berry Flavor Latte","green tea star Ice Music","Cocoa Shard star Ice Music","Caramel Macchiato","Classic Chocolate","Coffee, Smith .","Hot Milk","Oriental Beauty","Ice Mocha","Cappuccino","American Coffee","Double fruit Juice"]4 forXinchRange (0,12):5 Print(D[x])
Python iterator (2)--Implement for loop