Iteration – While Loops

Slides:



Advertisements
Similar presentations
Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
Advertisements

Looping Structures: Do Loops
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
Neal Stublen Loop Structure  Sometimes it’s useful to repeat yourself  The same actions need to occur more than once  Ensures.
CS0004: Introduction to Programming Repetition – Do Loops.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
James Tam Loops In Python In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
True BASIC Ch. 6 Practice Questions. What is the output? PRINT X LET X = -1 PRINT X FOR X = 4 TO 5 STEP 2 PRINT X NEXT X PRINT X END.
BACS 287 Programming Logic 3. BACS 287 Iteration Constructs Iteration constructs are used when you want to execute a segment of code several times. In.
Intro to Java while loops pseudocode. 1 A “Loop” A simple but powerful mechanism for “making lots of things happen!” Performs a statement (or block) over.
Fundamentals of Python: From First Programs Through Data Structures
Fundamentals of Python: First Programs
Control Structures FOR Statement Looping.
Mastery Objective: Students will understand how to use while loops in computer programming.
Computer Science 111 Fundamentals of Programming I The while Loop and Indefinite Loops.
 Wednesday, 9/18/02, Slide #1 CS106 Introduction to CS1 Wednesday, 9/18/02  QUESTIONS?? HW #1 due today at 5!!  Today: Loops, and two new data types.
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
Even more problems.. Mean (average) I need a program that calculates the average of student test scores. I need a program that calculates the average.
Course A201: Introduction to Programming 09/16/2010.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Loops and Simple Functions CS303E: Elements of Computers and Programming.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
More Sequences. Review: String Sequences  Strings are sequences of characters so we can: Use an index to refer to an individual character: Use slices.
9. ITERATIONS AND LOOP STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Testing Programs with Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Design Document Sample Given two concentrated circles with different radii, calculate the area which falls inside the big circle but outside the small.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
More about Iteration Victor Norman CS104. Reading Quiz.
A-level Computing Programming challenge 1: Fizzbuzz
Week of 12/12/16 Test Review.
Lecture 7: Repeating a Known Number of Times
Lesson 05: Iterations Class Chat: Attendance: Participation
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Think What will be the output?
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Python - Iteration Iteration
Computer Science 101 While Statement.
Do it now activity Green pen activity in books.
While Loops (Iteration 2)
Writing Functions( ) (Part 5)
Writing Functions( ) (Part 5)
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Programming Fundamentals Lecture #6 Program Control
Lesson 05: Iterations Topic: Introduction to Programming, Zybook Ch 4, P4E Ch 5. Slides on website.
Repetition Structures
Chapter (3) - Looping Questions.
Higher Computing Using Loops.
IST256 : Applications Programming for Information Systems
LOOPS BY: LAUREN & ROMEO.
Module 4 Loops and Repetition 2/1/2019 CSE 1321 Module 4.
Let’s all Repeat Together
A LESSON IN LOOPING What is a loop?
Introduction to Computer Science
Repetition Statements (Loops) - 2
Another Example Problem
Introduction to Computer Science
WEEK 8 COURSE PROJECT PRESENTATION NAME: ALEXANDER WEISS CLASS: CIS115.
GCSE Computing:: While Loops
Arrays & Loops.
Arrays & Loops.
Starter Look at the hand-out.
CMPT 120 Lecture 13 – Unit 2 – Cryptography and Encryption –
Module 4 Loops and Repetition 9/19/2019 CSE 1321 Module 4.
Presentation transcript:

Iteration – While Loops Python Iteration – While Loops

biscuits = 3 Iteration What does iteration mean? Answer: Computing term for repeatedly doing a set of actions biscuits = 3

biscuits = 3 Iteration There are two types of iteration: Definite - Counter Controlled Indefinite – Condition Controlled In this presentation we will be considering indefinite This means the loop will continue until the condition is met. It could be the condition is never met which means it is infinite biscuits = 3

While biscuits > 0 eat_biscuit biscuits = biscuits -1 Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1

While biscuits > 0 eat_biscuit biscuits = biscuits -1 Iteration While biscuits > 0 eat_biscuit biscuits = biscuits -1

Activity 1 Open a new Python code window and enter the following code: Save it as While Loop Modify your code to: Ask the user how many times to loop. Replace the constant 5 with the variable you have created Only print the value of count when it is equal to 3 Print the value of count when the loop has finished

Activity 2 Guess My Number Download the starter code: http://bit.ly/2JPZ7qA Or https://www.ict4u.net//Python/includes/CodeTxt/Guess%20My%20Number.txt to your Python Coding folder. Save as Guess My Number The code contains two syntax errors. Fix the code to make it work

Activity 2 Guess My Number Extending the code Give clues to the player prompting them if their guess was too high or too low Count the number of times the player guesses and report this number at the end of the game Limit the number of guesses a player can attempt an a game to a number you choose Stop the game when the limit has been reached