Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet89/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   85   86   87   88   89   90   91   92   ...   453
70

CHAPTER 4
Using ArrAys And ColleCtions
The actual detection takes place with the code, 
Number % Divisor
. If the output of this calculation 
is 0, then there isn’t any remainder, and you’ve found the divisor you wanted. At this point, the code 
outputs the two numbers that will result in the target number when multiplied, such as 4 = 2 * 2. 
After printing out the result, the inner loop can stop — it’s found the divisor you wanted and deter-
mined that the number isn’t prime.
However, some numbers won’t have a divisor because they are prime. In this case, the 
else
clause 
takes over. The 
for
loop literally falls through to the 
else
clause and performs some other processing 
when the 
for
loop fails. Figure 4-9 shows the output from this example.
FIguRE 4-9: 
Using break makes it possible to stop loop processing, while else gives an alternative output.
Processing Arrays using the continue Clause
A loop sometimes finishes the task that it’s performing with a particular sequence or array elements
but you want to continue processing with the next element. In this case, you use the 
continue
clause 
rather than the 
break
clause of the loop. The 
continue
clause will continue with the next loop and 
bypass the rest of the current loop. Listing 4-10 shows an example of how you can use the 
continue
clause to request specific input from the user.
lISTINg 4-10: 
 Using continue to process sequences
# Define a list of keywords.
Keywords = [‘RED’, ‘YELLOW’, ‘BLUE’]
# Define a variable to detect a correct entry.
IsCorrect = False
# Create a loop to query the user about the keyword.
while not IsCorrect:
# Ask the user for the keyword.
Answer = raw_input(‘Type a keyword: ‘).upper()
# Detect a correct keyword.
if Answer in Keywords:
print ‘Congratulations, you provided the keyword!’
548592c04.indd 70
2/24/10 12:47:37 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   85   86   87   88   89   90   91   92   ...   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