Computer Science 101 For Statement. For-Statement The For-Statement is a loop statement that is especially convenient for loops that are to be executed.

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Computer Science 101 Lists in Python. The need for lists Often we need many different variables that play a similar role in the program Often we need.
Computer Science 101 While Statement. Iteration: The While-Statement The syntax for the While- Statement is while : The syntax for the While- Statement.
While loops.
Looping Structures: Do Loops
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS150 Introduction to Computer Science 1
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
Chapter 4 Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
Files in Python Input techniques. Input from a file The type of data you will get from a file is always string or a list of strings. There are two ways.
CSCI N201: Programming Concepts Copyright ©2005  Department of Computer & Information Science Working with Loops.
Simple Python Loops Sec 9-7 Web Design.
The for-statement. Different loop-statements in Java Java provides 3 types of loop-statements: 1. The for-statement 2. The while-statement 3. The do-while-statement.
Computer Science 101 Lists in Python. The need for lists Often we need many different variables that play a similar role in the program Often we need.
General Programming Introduction to Computing Science and Programming I.
8 For-Statements © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming 1.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Working with arrays (we will use an array of double as example)
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
For loops in programming Assumes you have seen assignment statements and print statements.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
COSC 235: Programming and Problem Solving Ch. 2: Your first programs!!! Instructor: Dr. X.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Python Arrays. An array is a variable that stores a collection of things, like a list. For example a list of peoples names. We can access the different.
Python break,continue and pass Statements. The break Statement: for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter.
solve x + (-16) = -12 solve x + (-16) = X = 4.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
1 Looping Dale/Weems/Headington. 2 KA/JS/P Warning l Save your work often! l In the Khan Academy, JavaScript environment, infinite loops will lock up.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Tutorial 9 Iteration. Reminder Assignment 8 is due Wednesday.
Expressions Methods if else Statements Loops Potpourri.
COMP Loop Statements Yi Hong May 21, 2015.
Computer Science 101 If Statement. Python Relational Operators.
1 Week 9 Loops. 2 Repetition: Loops l Structure: »Usually some initialization code »body of loop »loop termination condition l Several logical organizations.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Loops and Simple Functions COSC Review: While Loops Typically used when the number of times the loop will execute is indefinite Typically used when.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Lecture 9 For Loops.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Python Flow of Control CS 4320, SPRING Iteration The ‘for’ loop is good for stepping through lists The code below will print each element in the.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
UCT Department of Computer Science Computer Science 1015F Iteration
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Introduction to Computing Science and Programming I
Topic: Iterative Statements – Part 1 -> for loop
Computer Science 101 While Statement.
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Conditional Loops.
Determinate Loops with the
Outline Altering flow of control Boolean expressions
Lists in Python.
Unary Operators ++ and --
More Loops.
More Loops.
Let’s all Repeat Together
A LESSON IN LOOPING What is a loop?
Python Basics with Jupyter Notebook
Loops and Simple Functions
Repetition (While Loop) LAB 9
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
REPETITION Why Repetition?
Presentation transcript:

Computer Science 101 For Statement

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.

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.

Python Session

Find Largest Example

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]

Range Example

Find Largest Once More