BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.

Slides:



Advertisements
Similar presentations
Microsoft® Small Basic
Advertisements

Loops (Part 1) Computer Science Erwin High School Fall 2014.
Python Magic Select a Lesson: Why Learn to Code? Basic Python Syntax
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Program Design and Development
Introducing Loop Statements Liang, pages Loop statements control repeated execution of a block of statements Each time the statements in the block.
Copyright © Texas Education Agency, Computer Programming For Loops.
5.05 Apply Looping Structures
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
110-K1 Iterations (1) Up to now, need to call the procedure again (e.g. click again on a command button) To repeat a piece of code: Can also use loops:
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved For Loops October 16, 2013 Slides by Evan Gallagher.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Bug Session Four. Session description Objectives Session activities summary Resources Prior knowledge of sequencing instructions using Bug Bug website.
B065: PROGRAMMING OPERATORS AND SELECTION 2. Starter  What do each of the following mean? Write an example of how each could be used. Symbol = <
By the end of this session you should be able to...
CPS120 Introduction to Computer Programming The Programming Process.
1 CS 106 Computing Fundamentals II Chapter 61 “Loops” Herbert G. Mayer, PSU CS Status 7/29/2013 Initial content copied verbatim from CS 106 material developed.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
30/10/ Iteration Loops Do While (condition is true) … Loop.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
 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.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
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.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
ITP © Ron Poet Lecture 7 1 Repetition. ITP © Ron Poet Lecture 7 2 Easing Repetitive Tasks  Many computing task are repetitive.  Checking all known foods.
Counting Loops.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
Intro to Loops 1.General Knowledge 2.Two Types of Loops 3.The WHILE loop 1.
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Identify the Appropriate Method for Handling Repetition
FOP: While Loops.
UNIT 5 Lesson 15 Looping.
REPETITION CONTROL STRUCTURE
Think What will be the output?
Chapter 5: Control Structure
Lecture 07 More Repetition Richard Gesick.
Algorithm and Ambiguity
Introducing Do While & Do Until Loops & Repetition Statements
Iterations Programming Condition Controlled Loops (WHILE Loop)
Lecture 4B More Repetition Richard Gesick
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Creativity in Algorithms
More Loops.
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
Do While (condition is true) … Loop
Coding Concepts (Basics)
` Structured Programming & Flowchart
Algorithm and Ambiguity
3.1 Iteration Loops For … To … Next 18/01/2019.
Computer Science Core Concepts
For Loops (Iteration 1) Programming Guides.
PYTHON: BUILDING BLOCKS Sequencing & Selection
Flowcharts and Pseudo Code
A LESSON IN LOOPING What is a loop?
Prepared By: Deborah Becker
While Loops in Python.
Presentation transcript:

BO65: PROGRAMMING ITERATION 1

Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while intCounter <10 console.writeline(intCounter) intCounter = intCounter+1 Loop

Objectives Understand what is meant by iteration in programming. Explore different types of iteration: DO loops and FOR loops. Understand the use of iteration in programming.

What is Iteration? Iteration is simply the repetition of a sequence of (one or more) statements. In programming, this is often referred to as a loop. The statements might not be executed at all (zero repetitions), or may be executed at least once. Eventually, something must stop the repetition, allowing the program to continue further.

Why bother with iteration? Imagine an array of 1000 entries, each containing a payment due from customers. At the end of the month, £20 is added on to each customer. You would need to write at least 1000 lines of code to do this. You could just loop through the array and add it on in about 6 lines of code! Imagine counting the number of letter “e’s” which appear in this slide. This would involve you going through the slide and checking each word, then adding 1 to a tally every time you come across one. Alternatively, a loop could go through the slide and do this for you. A loop is used when you are performing repetitive tasks.

Being Cautious About Loops The distinction between checking before starting any processing, and checking at the end of each run through the statements is a fundamental one. Putting the check in the wrong place is one of the commonest causes of errors when dealing with loops in programs. For example: – Would you issue a bill to a customers BEFORE checking if they owed anything or would you check each customers balance before printing the bill.

DO Loops We start by looking at loops where the number of repetitions (which might possibly be zero, remember) is determined by checking some condition. These are known as "Do Loops.” By “Do Loop” we just mean “Do this, if something is true or false.” For example “If there is a sale, go through each item in stock and deduct 10%.” When using “Do loops,” there are two places where we might choose to do the check: – before starting each repetition, i.e. at the beginning of the loop – just after finishing each repetition, i.e. at the end of the loop If we check the condition at the end of the loop, we are certain to execute the statements at least once.

Using a DO Loop You simply tell the computer to do something whilst a condition is true. It then cycles through the loop until the condition becomes false. The condition is checked EVERY cycle. Do While condition statement(s) Loop Simple examples of such conditions might be: - intOne = 0 total < 100 (intCount < 250) And (strName = "Smith") Let’s look at some examples.

Variations of the DO Loop Do Until … Loop - condition tested before first entry to the loop Do Until strName = “chris” console.clear() console.writeline(“Enter your name”) strName = console.readline() Loop Do … Loop Until … - condition tested after first execution of the loop Do console.clear() console.writeline(“Enter your password”) strPassword = console.readline() Loop until strPassword = “chaching” Do … Loop While … - condition tested after first execution of the loop

Today’s Task Loops are a very difficult concept to grasp. We will work through some activities, but will go through the first one together, writing an algorithm for it. Prep tasks: Complete questions in Task 14 Ready to program? Complete the programming tasks in Task 14: Loops in Programming Tasks.

Task 2 Now you have written the code to each task, try changing the type of loops and see what happens. E.g. if you have used a Do…Loop Until loop, change it to a Do While…Loop, and note down how it is different. Can you explain it?

Required Reading Each week you will be given required reading. If you fail to do this, you will 100% find the lessons which follow it EXTREMELY difficult. Before next lesson you should have read: Pre-reading 30-38

Plenary Let’s go through your programming tasks. Each person will come up and ask to show their solution to each of the loops programming tasks.