fork download
  1. # FOR loop
  2. print("Contoh FOR loop:")
  3. for i in range(5): # dari 0 sampai 4
  4. print("Kedip ke-", i+1)
  5. print("Selesai FOR\n")
  6.  
  7. # WHILE loop
  8. print("Contoh WHILE loop:")
  9. i = 0
  10. while i < 5:
  11. print("Kedip ke-", i+1)
  12. i += 1
  13. print("Selesai WHILE\n")
  14.  
  15. # DO WHILE loop (simulasi di Python)
  16. print("Contoh DO WHILE loop:")
  17. i = 0
  18. while True:
  19. print("Kedip ke-", i+1)
  20. i += 1
  21. if i >= 5: # kondisi berhenti
  22. break
  23. print("Selesai DO WHILE\n")
Success #stdin #stdout 0.02s 7276KB
stdin
Standard input is empty
stdout
Contoh FOR loop:
('Kedip ke-', 1)
('Kedip ke-', 2)
('Kedip ke-', 3)
('Kedip ke-', 4)
('Kedip ke-', 5)
Selesai FOR

Contoh WHILE loop:
('Kedip ke-', 1)
('Kedip ke-', 2)
('Kedip ke-', 3)
('Kedip ke-', 4)
('Kedip ke-', 5)
Selesai WHILE

Contoh DO WHILE loop:
('Kedip ke-', 1)
('Kedip ke-', 2)
('Kedip ke-', 3)
('Kedip ke-', 4)
('Kedip ke-', 5)
Selesai DO WHILE