5.5: The 'for' Loop
Please read this chapter. This chapter discusses for loop. This loop is more compact than the while and do loops and automatically updates the loop counter at the end of each iteration.
Attempt this ungraded quiz.
Please read this chapter. Make sure to click on the arrow buttons to navigate to each webpage. You may also click on the sound icon at the top of the webpage to listen to the MP3. This chapter discusses the for loop in greater detail as well as the scope of variables in the for loop.
Attempt this ungraded quiz.
Please watch the 11-minute lecture. This lecture explains loops by applying them to a simple application, manipulating lists. Unlike the while loop, the for loop does not require a statement in the body of the loop that updates the control variable. Please note that the for loop is explained using Python programming language.
Watch these lectures. The first lecture uses a for loop to calculate the factorial of a natural number greater than or equal to 0. Remember to focus on the design or algorithm of the program and the semantics of the program statements.
In the second, note how Khan verifies the program by stepping through it. In the previous video, he also ran it several times to check it out.
In the third lecture, Khan documents the design of the factorial program by flowcharting it; this is the design of the program, which logically is done before writing the program.