For Loops

Narrated by Saumya Jain

Introduction

  • In the prior chapter we earned about "if" statements
  • In this chapter we learn how to loop
  • Our program can run the same block of code over and over
  • This chapter covers "for" loops
    • Loop a certain number of times, or for each item in a list
  • Next chapter covers "while" loops
    • Loop until something happens or a condition is false

Introduction to Looping

For Loops

Loop a certain number of times, or for each item in a list.

While Loops

Loop until something happens.

for student in student_list:
while not closed:

For Loops

Using the Counter Variable

Counting By Numbers Other Than One

Nesting Loops

Keep a Running Total

s=\sum\limits_{n=1}^{100}n
s=1+2+3+4+5 \ldots 98+99+100

Review

11 For Loops

By Paul Craven

11 For Loops

  • 22
Loading comments...

More from Paul Craven