Lesson 7 of 55 · Python
Loops – While
Duration: 20 minutes
Lesson 7 of 55 · Python
Duration: 20 minutes
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.\n\npython\ncounter = 0\nwhile counter < 5:\n print('Count:', counter)\n counter += 1\n\n\nWhen counter reaches 5, the condition becomes false and the loop exits.\n