LimioLearn in Flow
🏆 Đấu trường
Đăng nhậpĐăng ký
← Programming for Data Science

Bạn đang xem thử công khai

Đăng nhập để lưu tiến độ, làm bài tập, thảo luận và nhận phản hồi.

Đăng nhập
Module 1: Fundamentals of Python Programming

1.8 for and while Loops

In / Lưu PDF

1.8 for and while Loops

After this unit you will: choose the right kind of loop and predict exactly how many times it runs.

Key points

  • range(start, end, step) stops just before end: range(2, 6) gives 2, 3, 4, 5.
  • break exits the loop; continue skips the current iteration.
  • An else after a loop runs only if the loop was not ended by break.
  • Use for when the number of iterations is known in advance; use while to repeat until a condition becomes false.