Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet73/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   69   70   71   72   73   74   75   76   ...   453
LISTINg 3-6: 
 Looping through data using while
# Create an array of strings.
MyList = ‘Hello’, ‘Goodbye’, ‘Red’, ‘Green’
# Define a counter variable.
Counter = 0
# Define the current string.
ThisString = ‘’
# Process the array. 
while ThisString != ‘Green’:
# Get the next value.
ThisString = MyList[Counter]
# Display the individual values.
print ‘The current value is:’, ThisString
# Update the counter.
Counter+=1
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
548592c03.indd 52
2/24/10 12:47:30 PM
www.finebook.ir


Performing Enumerations
 

 
53
This example begins with the same array as shown in Listing 3-5. In order to make the 
while
loop 
work, the code must define 
Counter
, which keeps track of the current array element. The code also 
defines 
ThisString
, which holds the current array value. As you can already see, the 
while
loop 
isn’t nearly as automatic as the 
for...in
loop, but it does provide considerable flexibility.
In this case, the 
while
loop continues to run until 
ThisString
is equal to 
‘Green‘
, the last value in 
the array. As always, the 
while
statement ends with a colon and every indented statement after it is 
part of the 
while
structure.
The code relies on 
Counter
to access the individual array elements. You simply provide Counter as an 
index into 
MyList
using 
MyList[Counter]
. The code then prints out the value found in 
ThisString

Finally, the code updates Counter. Notice that IronPython supports the use of the 
+=
shortcut. The out-
put from this application appears in Figure 3-4.
FIgURE 3-4: 
Use the while loop when you need to perform tasks an indeterminate number of times.
You might have noticed that IronPython doesn’t appear to support the vast array 
of loop statement subsets found in other languages. For example, there isn’t any 
version of the 
while
 statement that tests for the condition after executing the code 
the first time. In general, this apparent limitation actually makes things consider-
ably easier. You simply need to write your code in such a way as to accommodate 
the “test first” orientation of the IronPython 
while
 loop.

Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish