Introduction to Python ProgrammingXYZ Homework Edition

⇩ Download ▾

5.6 Chapter summary

Highlights from this chapter include:

At this point, you should be able to write programs with loop constructs. The programming practice below ties together most topics presented in the chapter.

Table 5.4 Chapter 5 reference.
FunctionDescription
range(end)Generates a sequence beginning at 0 until end with step size of 1.
range(start, end)Generates a sequence beginning at start until end with step size of 1.
range(start, end, s)Generates a sequence beginning at start until end with the step size of s.
Loop constructsDescription
while loop # initialization while expression:   # loop body # statements after the loop
for loop # initialization for loop_variable in container:   # loop body # statements after the loop
Nested while loop while outer_loop_expression:   # outer loop body (1)   while inner_loop_expression:     # inner loop body   # outer loop body (2) # statements after the loop
break statement # initialization while loop_expression:   # loop body   if break_condition:     break   # remaining body of loop # statements after the loop
continue statement # initialization while loop_expression:   # loop body   if continue_condition:     continue   # remaining body of loop # statements after the loop
Loop else statement # initialization for loop_expression:   # loop body   if break_condition:     break   # remaining body of loop else:   # loop else statement # statements after the loop

Adapted from Introduction to Python Programming by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.