Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,

Slides:



Advertisements
Similar presentations
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Advertisements

Tutorial 12 Working with Arrays, Loops, and Conditional Statements
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part 2.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 7: Program flow control.
Python Control of Flow.
Introduction to Programming Workshop 2 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Lecture Set 5 Control Structures Part D - Repetition with Loops.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
If statements while loop for loop
Roles of Variables with Examples in Python ® © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
For loops in programming Assumes you have seen assignment statements and print statements.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Course A201: Introduction to Programming 09/30/2010.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Visual Basic.NET BASICS Lesson 11 List Boxes, For Next Loops, and Label Settings.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
Controlling Program Structures. Big Picture We are learning how to use structures to control the flow of our programs Last week we looked at If statements.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
More about Iteration Victor Norman CS104. Reading Quiz.
Topic: Iterative Statements – Part 1 -> for loop
Python Loops and Iteration
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Visual Basic 6 (VB6) Data Types, And Operators
Python: Control Structures
CS 115 Lecture 8 Structured Programming; for loops
Think What will be the output?
Ch 7: JavaScript Control Statements I.
Repetition: the for loop
Web Programming– UFCFB Lecture 16
Lab 2 : Structures Muhammad Zaigham Abbas Shah DIGITAL INSTRUMENTATION SYSTEMS.
Chapter 5 Structures.
Arrays, For loop While loop Do while loop
FLOW OF CONTROL.
Programming Fundamentals Lecture #6 Program Control
Topics Introduction to File Input and Output
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
3 Control Statements:.
Topics Introduction to Repetition Structures
` Structured Programming & Flowchart
LabVIEW.
Introduction to Repetition Structures
ICT Programming Lesson 3:
15-110: Principles of Computing
A LESSON IN LOOPING What is a loop?
For loops Taken from notes by Dr. Neil Moore
The structure of programming
Repetition: the for loop
Topic: Loops Loops Idea While Loop Introduction to ranges For Loop
Topics Introduction to File Input and Output
LOOPS For EE 201 C10-1 SPRING 2012.
Topic: Iterative Statements – Part 2 -> for loop
Introduction to Python
Presentation transcript:

Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional, where blocks of instructions are executed only if some condition is met 3. repeating, where blocks of instructions are repeated a number of times

Computer Program Flow Block of instructions

The for Loop … syntax Loops are used to repeat an operation or to process something more than once. A Python for loop: iterates through each value in a sequence. a count controlled loop that always executes a specified number of times The syntax is: for variable in sequence: # for clause statement # code executed every statement(s) # time the loop iterates

The for Loop … behaviour for variable in sequence: statement statement(s) variable takes on the 1st value in the sequence; statements in the loop body are executed variable takes on the 2 nd value in the sequence; statements in the loop body are executed variable takes on the 3 rd value … … repeat until all values in the sequence handled a sequence holds multiple items of data, stored one after the other

The for Loop … sequence (1) using the range function => range([start,] limit [[, increment]]) read as: from start (defaults to 0) up to but not including limit in steps of increment (defaults to 1) for var in range(5): for var in range(0,5): for var in range(0,5,1):

The for Loop … example # Assignment 1 Question 2 – do 3 tests for count in range (3):  for clause course = input("Enter favourite course: ") mark = input("Enter grade you hope to get: ") print() print("You hope to get", mark, "in your favourite course", course, ".")

The for Loop … sequence Defining the sequence *: (2) you can explicitly list the numbers in the sequence, e.g. for number in [0,1,2,3,4,5]: print(number) where: [0,1,2,3,4,5] is a Python list * Python has various sequence type objects that we have not introduced yet, e.g. strings, tuples, and more about lists.

The for Loop … sequence (3) the sequence items are handled in the order they appear e.g. for number in [123, 5, -27, 15.5]: print(number) for course in ["MA100", "MA110", "MA103"]: print(course) for name in ["Peter", "Paul", "Mary"]: print(name)