Download presentation
Presentation is loading. Please wait.
Published byDarren Harris Modified over 9 years ago
1
Computer Science 101 For Statement
2
For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed a specific number of times (not controlled by user input, etc.). The For-Statement is a loop statement that is especially convenient for loops that are to be executed a specific number of times (not controlled by user input, etc.). The For-Statement is also convenient for working with lists. The For-Statement is also convenient for working with lists.
3
For-Statement (cont.) Syntax: for in : Syntax: for in : The variable is called the loop index. The variable is called the loop index. Semantics: For each value in the list, the loop index takes on the value and the loop body is executed. Semantics: For each value in the list, the loop index takes on the value and the loop body is executed.
4
Python Session
6
Find Largest Example
7
Range range provides a list of consecutive numbers. range provides a list of consecutive numbers. If num is a positive integer, then range(num) gives the list [0,1, …, num-1]If num is a positive integer, then range(num) gives the list [0,1, …, num-1] If num1 < num2, then range(num1, num2) gives the list [num1, num1+1, …, num2-1]If num1 < num2, then range(num1, num2) gives the list [num1, num1+1, …, num2-1]
8
Range Example
9
Find Largest Once More
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.