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.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Noadswood Science,  To set out and solve an identified problem Monday, August 10, 2015 Box ‘a’Box ‘b’ 23 Box a is smaller than Box b…
Presented by Joaquin Vila Prepared by Sally Scott ACS 168 Problem Solving Using the Computer Week 12 Boolean Expressions, Switches, For-Loops Chapter 7.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
An Introduction to Textual Programming
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
By the end of this session you should be able to...
Python Repetition. We use repetition to prevent typing the same code out many times and to make our code more efficient. FOR is used when you know how.
For loops in programming Assumes you have seen assignment statements and print statements.
CS 100 Introduction to Computing Seminar October 7, 2015.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
GCSE Computing: Programming GCSE Programming Remembering Python.
CPSC 217 T03 Week V Part #1: Iteration Hubert (Sathaporn) Hu.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
COMP Loop Statements Yi Hong May 21, 2015.
In-class program development 1 You are to develop a simple calculator which will allow the user (you, also) to perform the following operations: The first.
GCSE Computing: Programming GCSE Programming Remembering Python.
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
For Loop GCSE Computer Science – Python. For Loop The for loop iterates over the items in a sequence, which can be a string or a list (we will discuss.
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.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Starter What does the following code do?
Lesson #5 Repetition and Loops.
Topic: Iterative Statements – Part 1 -> for loop
Data Types and Conversions, Input from the Keyboard
Quiz # 02 Design a data type Date to hold date
CS161 Introduction to Computer Science
Lesson #5 Repetition and Loops.
Think What will be the output?
Lesson 3 - Repetition.
Python - Iteration Iteration
Repetition: the for loop
Computer Science 101 While Statement.
Do it now activity Green pen activity in books.
Iterations Programming Condition Controlled Loops (WHILE Loop)
While Loops (Iteration 2)
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Learning to Program in Python
Learning to Program in Python
Lesson #5 Repetition and Loops.
Use proper case (ie Caps for the beginnings of words)
Introduction to pseudocode
Chapter (3) - Looping Questions.
Bryan Burlingame 28 November 2018
Loops CIS 40 – Introduction to Programming in Python
Coding Concepts (Basics)
Python 21 Mr. Husch.
Flowcharts and Pseudo Code
A LESSON IN LOOPING What is a loop?
CHAPTER 6: Control Flow Tools (for and while loops)
Python Basics with Jupyter Notebook
Lesson #5 Repetition and Loops.
Repetition: the for loop
Lecture 13 Teamwork Bryan Burlingame 1 May 2019.
CSE 231 Lab 2.
Hint idea 2 Split into shorter tasks like this.
Learning Intention I will learn about the standard algorithm for input validation.
Week 7: Computer Tools for Problem Solving and Critical Thinking
What you need to do… Drag the pieces of code into the correct order like you can see in the EXAMPLE below. print ( “ int input ) = + Hello world chr ord.
Topic: Iterative Statements – Part 2 -> for loop
Starter Look at the hand-out.
Iteration – While Loops
Presentation transcript:

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. This lesson we are going to look at Iteration with different kinds of loops.

Selection To make a choice. To do something in response to a test or condition In computing this is achieved using If statements

Iteration The process of doing something again and again. Either for a set number of times or until (while) a condition is met.

Indent/Indentation To set in or back from the margin, as the first line of a paragraph. See code below: word = "indentation" for letter in word: print (letter) print ("defines the loop")

Learning Objective The Objective of today’s lesson is to understand the use of iteration in a computer program.

Learning Outcomes LO1: know what iteration is in terms of computing and the structures that are used in python. (D-G) LO2: Apply knowledge to make the correct choice of structure to solve a given problem.(C) LO3: Create a working solution to a problem using the appropriate structure.(C+) (Grade above C will depend on quality of code and how well it is commented and documented)

For Example X = input(“please enter a number”) X = int(X) X = input(“please enter a number”) #get user input X = int(X) #change to integer #assign user input to variable X and cast X to integer data type X = int(input(“please enter a number”))

For / While Demo For Loop Used for fixed number of iterations For i in range (0,20): print(“Down”) print(“Up”) print(str(i)) Print(“Thank You”) While Loop Used to repeat an unknown number of times, until a condition is met bored = n While bored == n: print(“Down”) print(“Up”) bored = input (“Are you bored yet y/n”) Print(“thank You”)

Why indentation is vital word = "indentation" for letter in word: print (letter) print ("defines the loop") >>> i defines the loop n defines the loop d defines the loop e defines the loop n defines the loop t defines the loop a defines the loop t defines the loop i defines the loop o defines the loop n defines the loop >>> word = "indentation" for letter in word: print (letter) print ("defines the loop") >>> i n d e n t a t i o n defines the loop >>>