Cara Menghentikan Infinite Loops While di Python

  WritingSkills.my.id - Pada tutorial sebelumnya, Contoh While Loops dan Infinite Loops , kita telah mempelajari cara membuat kode perulang...
 Cara Menghentikan Infinite Loops While di Python

WritingSkills.my.id - Pada tutorial sebelumnya, Contoh While Loops dan Infinite Loops, kita telah mempelajari cara membuat kode perulangan while. Pada pembahasan kali ini, kita akan belajar bagaimana cara untuk menghentikan perulangan while yang mengulang eksekusi blok kodenya sendiri secara terus-menerus. 
while True:
  print("dan lagi")

Untuk menghentikan sebuah perulangan (loop), kita mulai dengan membuat sebuah variabel di luar kode perulangan. 
terus_lanjutkan = True

while True:
  print("dan lagi")

Kita menggunakan variabel tersebut di dalam sebuah kondisional (condition) untuk menentukan apakah perulangan akan mengeksekusi kode bloknya sendiri atau tidak. Sebagai contoh, kita akan membuat condition terus_lanjutkan == True.
terus_lanjutkan = True

while terus_lanjutkan == True:
  print("dan lagi")

Di dalam blok kode perulangan while, kita akan menghentikan proses looping dengan memberikan variabel terus_lanjutkan nilai False sehingga kondisional yang ada menjadi False atau kebalikan dari True. Sebagai contoh, cek kode berikut:
terus_lanjutkan = True

while terus_lanjutkan == True:
  print("dan lagi")
  terus_lanjutkan = False
Contoh Kode Python untuk Menghentikan Infinite Loops While

Perulangan mengeksekusi keseluruhan kode bloknya karena variabel terus_lanjutkan bernilai True pada awalnya, tapi tidak mengeksekusi kode bloknya lagi karena kita telah mengatur nilai variabel tersebut menjadi False. Contohnya adalah kode barisan kode berikut:
terus_lanjutkan = True

while terus_lanjutkan == True:
  print("dan lagi")
  
  terus_lanjutkan = False
  
  print("satu kali lagi")
Contoh Kode Python untuk Menghentikan Infinite Loops While

Contoh kode Python untuk menghentikan perulangan lainnya adalah sebagai berikut:

Kode 1
terus_lanjutkan = True

while terus_lanjutkan == True:
  print("Teruslah berenang")
  terus_lanjutkan = False

Kode 2
terus_mainkan = True

while terus_mainkan == True:
  print("Sekarang Memainkan: Dolce Vita")
  terus_mainkan == False

Kode 3
auto_pilot = False

while auto_pilot == True:
  print("Autopilot on: vroom!")
  auto_pilot == False

COMMENTS

Nama

Belajar C#,6,Belajar Coding,66,Belajar HTML,11,Belajar JavaScript,9,Belajar PHP,1,Belajar Python,38,Business Letters,18,Business Memos,3,Chord Gitar,2,Download,7,English Grammar,13,Info Unik,57,Main Gitar,9,MS. Office Tutorial,4,MS. Word Tutorial,4,Proyek JavaScript,2,Proyek Python,9,Surat Lamaran,4,
ltr
item
My Writing Skills: Cara Menghentikan Infinite Loops While di Python
Cara Menghentikan Infinite Loops While di Python
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr1KJceKK_G4IBPzuNbhnLxL88ORSy6p5EN_Hl-57cp3VZOKzR8N24yWAOjh_5UpBcI_Dprod5dCCC4QayI7i4_5Tk2DRVoPhtYqN-wPZQy1-Tg6v2lwKkzoS0ZgrXOwtA5DHfik2RtkyR-pNHgNGPYctpnfnFg2Vq0KXkO1Hd8O9Du2TNBZsMQLL0ah81/w640-h320/Menghentikan-Infinite-Loops-While-Python.jpg
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr1KJceKK_G4IBPzuNbhnLxL88ORSy6p5EN_Hl-57cp3VZOKzR8N24yWAOjh_5UpBcI_Dprod5dCCC4QayI7i4_5Tk2DRVoPhtYqN-wPZQy1-Tg6v2lwKkzoS0ZgrXOwtA5DHfik2RtkyR-pNHgNGPYctpnfnFg2Vq0KXkO1Hd8O9Du2TNBZsMQLL0ah81/s72-w640-c-h320/Menghentikan-Infinite-Loops-While-Python.jpg
My Writing Skills
https://www.writingskills.my.id/2025/01/menghentikan-infinite-loops-while-python.html
https://www.writingskills.my.id/
https://www.writingskills.my.id/
https://www.writingskills.my.id/2025/01/menghentikan-infinite-loops-while-python.html
true
2523867061632956444
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content