Login
📚 Introduction to Python Programming
Chapters ▾
⇩ 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