Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools



Download 2,02 Mb.
Pdf ko'rish
bet104/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   100   101   102   103   104   105   106   107   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Avoiding Endless Loop
Have  you  ever  encountered  a  situation  where  your  phone  cannot  respond
irrespective of what you do? You even allowed it to stay for hours, yet no
solution.  You  decided  to  charge  it,  yet  to  no  avail.  Finally,  you  have  the
instinct  to  remove  the  battery  of  the  phone.  And  you  pressed  the  power
button and “boom” the phone came alive and responded perfectly. At least,
you had a way out.
What if after writing your program and decides to run it and suddenly your
key developed a fault? Or you forget the particular word to enter to exit the
program. Besides this, you can even face one of the worst challenge most
beginner face when using conditional statement – an endless loop. How do
you override this situation?
In  a  while  loop,  you  must  have  a  way  of  stopping  it  from  running
continuously. For instance, the loop below counts from 10 to 15:
number = 10
while number <= 15:
print(number)
number +=1
When this program is run, you will get the output as follow:
10
11
12


13
14
15
However,  let  us  assume  that  you  accidentally  forget  to  include  the  line
“number+=1)  in  the  program.  What  will  happen  when  Python  encounters
this program?
number = 10
while number <= 15:
print(number
The program will run continuously and never stop. The value of the number
will start at 10 but won’t change. Because of this, the conditional statement
number <=15 will evaluate to True at all times. Additionally, the while loop
will not stop because it will be printing 1o upon 10 throughout the program.
Don’t  beat  yourself  up  if  you  face  such  an  issue  because  virtually  all
programmers have accidentally written an infinite loop. If you find yourself
stuck in such a situation, take a glass of cooled water and quench your taste.
There is nothing to stress yourself about; you can use the CTRL+C button
to  escape  from  this  endless  loop.  Additionally,  you  can  close  the  Python
program.  To  avoid  such  an  endless  loop,  you  should  test  each  while  loop
and ensure the loop ends where it should.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   100   101   102   103   104   105   106   107   ...   126




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