Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Loops – While | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 7 of 55

·Python

Loops – While

20 minutes

Course progress13%

What you'll learn

Keep these ideas in mind as you work through the lesson.

3 points
  • `while <condition>:` starts a loop that runs while the condition is true.
  • Make sure the loop variable changes inside the block to avoid infinite loops.
  • Use `break` to exit early, and `continue` to skip to the next iteration.

Loops – While

A while loop repeats a block of code as long as a condition remains true. It’s crucial to modify the loop variable inside the body; otherwise you’ll create an infinite loop.

counter = 0
while counter < 5:
    print('Count:', counter)
    counter += 1

When counter reaches 5, the condition becomes false and the loop exits.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonControl Flow – If StatementsContinue to lesson 8Loops – ForBack to Python Fundamentals curriculum