Python While Loops

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Python Loops

Python has two primitive loop commands: -while loops -for loops

The break statement

With the break statement we can stop the loop even if the while condition is true

The continue statement

With the continue statement we can stop the current iteration, and continue with the next

The while loop

With the while loop we can execute a set of statements as long as a condition is true

Continue to the next iteration if i is 3

i = 0 while i < 6: i += 1 if i == 3: continue print(i)

Print i as long as i is less than 6

i = 1 while i < 6: print(i) i += 1 ***Remember to increment i, or else the loop will continue forever

Exit the loop when i is 3

i = 1 while i < 6: print(i) if i == 3: break i += 1


Set pelajaran terkait

Social Problems 13th Movie: Final

View Set

Practice Questions for Last Five Weeks of Material

View Set

Orga_MCQ_Ch9_Competences, and Technology

View Set

Chapter 7: Thinking and Intelligence Study Guide Psychology Part 1

View Set

Chapter 0, Linux Ch. 7&8, Linux Chapter 2, Linux Chapter 1, Linux Test chapters 4-9

View Set