Introduction to Repetition

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

Programming TBE 540 Farah Fisher. Objectives After viewing this presentation, the learner will be able to… Given a task, create pseudocode Given pseudocode,
Repeating Actions While and For Loops
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 5: Looping by Tony.
Announcements The first graded lab will be posted Sunday 2/15 and due Friday 2/27 at midnight It is brand new, so please don’t hand in last semester’s.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Chapter 5: Loops and Files.
New ways of learning week Sign up at: Monday 25 th November Tuesday 26 th November Wednesday 27 th November Thursday.
COMP 1001: Introduction to Computers for Arts and Social Sciences Programming in Scratch Monday, May 16, 2011.
Pseudo Code Possibly one of the hardest skills to get to grips with in learning a programming language is developing the ability to take a problem and.
Logic Structure - focus on looping Please use speaker notes for additional information!
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.
PROGRAMMING ITERATION 2. Starter  Put the following code in order (write down the line numbers).  The program should display the numbers 1-24 on screen.
Review, Pseudocode, Flow Charting, and Storyboarding.
Adding 10 items to a list… lstTest.Items.Add(1) lstTest.Items.Add(2) lstTest.Items.Add(3) lstTest.Items.Add(4) lstTest.Items.Add(5) lstTest.Items.Add(6)
+ Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 5: Looping.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
For Code Next For Code Next A loop is a segment of a code that repeats (changing slightly each time)
Counting Loops.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Repetition: Definite Loops Sec 53 Web Design. Objectives The Student will: Understand loops and why they are used Understand definitive loops Know how.
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 Looping 5. The Increment and Decrement Operators 5.1.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Mastering LMC Coding Part #1 Introduction to Low Level Languages Introduction to Little Man computer Simple examples (demos) with video tutorials included.
Computer Programming 12 Lesson 6 – Loop structure By: Dan Lunney.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Sensor Information: while loops and Boolean Logic.
Comp1004: Loops and Arrays I Whiles, For and Arrays[]
REPETITION CONTROL STRUCTURE
Scratch: iteration / repetition / loops
Programming Mehdi Bukhari.
Worked Examples - Incremental Software Development Worked Example
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Python - Iteration Iteration
Web Programming– UFCFB Lecture 16
Looping and Repetition
Iteration with While You can say that again.
Creativity in Algorithms
While Loops and If-Else Structures
An Introduction to Control Structures
Alternate Version of STARTING OUT WITH C++ 4th Edition
Loops A loop is a repetition control structure.
The Integer Song.
CIS 16 Application Development Programming with Visual Basic
Chapter 6: Repetition Statements
3.1 Iteration Loops For … To … Next 18/01/2019.
An Introduction to Control Structures
A LESSON IN LOOPING What is a loop?
Class 4: Repetition Pretest Posttest Counting Flowchart these!
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Chapter 4: Repetition Structures: Looping
Introduction to Repetition
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Statements in C Programming
Selections and Loops By Sarah, Melody, Teresa.
Chapter 13 Conditional Repetition
Starter Look at the hand-out.
How to allow the program to know when to stop a loop.
Looping and Repetition
G6DICP - Lecture 5 Control Structures.
Presentation transcript:

Introduction to Repetition Loops Introduction to Repetition

Problem What do we do when we want to do something over and over again? E.g. Add the numbers 1 – 10 to a list box… lstTest.Items.Add(1) lstTest.Items.Add(2) lstTest.Items.Add(3) lstTest.Items.Add(4) lstTest.Items.Add(5) lstTest.Items.Add(6) lstTest.Items.Add(7) lstTest.Items.Add(8) lstTest.Items.Add(9) lstTest.Items.Add(10)

Solution Use a loop (repetition) Start of loop (set rules for number of repeats) Stuff we want to repeat End of Loop

Types of Loops Type 1 For-Next Loop   This loop repeats a section of code a specified number of times. So if we wanted to do a task 1000 times, this kind of loop is ideal. Type 2 While Loop (Pre processing) This loop repeats a section of code until a certain condition is met, that is the condition may be met on the first attempt or on the thousandth, we simply don’t know! Type 3 Do Loop (Post processing) Always runs the code once then continues until a certain condition is met.

To make loops work… For any loop to work we need to know three things… When the loop will start When the loop will end Where the loop is up to at a given point

Do While Loop Structure while (Condition) { //code to repeat goes here }

Things to Watch with Do While Loops! What is wrong with the following loops?

Indexes Counters and Accumulators

Indexes Counters and Accumulators Answers the question “How Many?” How many loan payments?

Indexes Counters and Accumulators Answer the question “How much?”