CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.

Slides:



Advertisements
Similar presentations
Chapter 6 - VB 2005 by Schneider1 Do Loop Syntax Do While condition statement(s) Loop Condition is tested, If it is True, the loop is run. If it is False,
Advertisements

Microsoft® Small Basic
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
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.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
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.
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
Repeating Program Instructions Chapter Microsoft Visual Basic.NET: Reloaded 1.
Iteration Conditional Loops Counted Loops. Charting the Flow of Control We’ve used flow charts to visualise the flow of control. The simplest form is.
5.05 Apply Looping Structures
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:
07/10/ Strings ASCII& Processing Strings with the Functions - Locate (Instr), Mid, Length (Len), Char (ChrW) & ASCII (Asc)
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
CW-V1 SDD 0601 Principals of Software Design and Development Variables Constants Data Types Error Handling Starter: BlockbustersBlockbusters.
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
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.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Tutorial 6 The Repetition Structure
Chapter 4 Looping Statements Adapted From: Starting Out with Visual Basic 2008 (Pearson)
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
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.
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
259 Lecture 11 Spring 2013 Advanced Excel Topics – Loops.
Counting Loops.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
For…Next Loops, Checked List Boxes, and Combo Boxes Chapter 5.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
List Boxes and Combo Boxes Provides a list of items to select from Various styles — choose based on Space available Need to select from an existing list.
Controlling Program Flow with Looping Structures
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
ARITHMETIC OPERATORS COMPARISON/RELATIO NAL OPERATORS LOGIC OPERATORS ()Parenthesis>Greater than &&And ^Exponentiation=>=
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
BO65: PROGRAMMING ITERATION 1. Starter  Write down what you think the code below outputs on screen: Dim intCounter as integer intCounter = 0 Do while.
National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
Learning Javascript From Mr Saem
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 6 Controlling Program Flow with Looping Structures.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
UNIT 5 Lesson 15 Looping.
Visual Basic 6 (VB6) Data Types, And Operators
Control Structures: Part 2
Starter Write a program that asks the user if it is raining today.
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
Control Structure Senior Lecturer
Higher Computing Using Loops.
Do … Loop Until (condition is true)
A LESSON IN LOOPING What is a loop?
Prepared By: Deborah Becker
ASP control structure BRANCHING STATEMENTS
Conditional Loops Counted Loops
Presentation transcript:

CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs

CW-V1 SDD 0902 Activity 1 - Review prior learning -10 mins A-Z Game Using scrap paper write down all the letters of the alphabet Eg A B C Now try to write down all keywords relating to VB but especially relating to the last lesson

CW-V1 SDD 0903 Learning outcomes Describe loops and their uses Describe various types of loop Create short programs which incorporate loops Explain to others code used to create loops Explain design methods used to design any program Apply learning to various scenarios (loop programs) Judge which loops to use in various scenarios Describe task 4 a

CW-V1 SDD 0904 What is a Loop? A piece of code that repeats Saves on a lot of typing! There are 3 main types in VB6  Do…While  Do…Loop Until  For…Next Block statements that contain code

CW-V1 SDD 0905 Code without Loops Dim UserNumber as Integer UserNumber = InputBox(“Please enter a number ”) If UserNumber < 10 then Print UserNumber UserNumber = UserNumber + 1 Print UserNumber EndIf If UserNumber < 10 then Print UserNumber UserNumber = UserNumber + 1 Print UserNumber EndIf

CW-V1 SDD 0906 LOOP 1 TYPE Do…While Loop Has a test at the beginning – like an if statement Will not execute (run) if the test result is false eg see below code - so if the user number gets to 10 or above it will stop running!! Make a new form in a new project and put code on a command button Sub cmdLooper_click Dim UserNumber as Integer UserNumber = InputBox(“Please enter a number ”) Print UserNumber Do While UserNumber < 10 UserNumber = UserNumber + 1 Print UserNumber Loop

CW-V1 SDD 0907 Do…While Flowchart Start End UserNumber < 10 ? Print UserNumber Loop Test Yes No

CW-V1 SDD 0908 LOOP 2 TYPE Do…Loop Until Has a test at the end of the statement This means the loop will always execute at least once (it will run once because you don’t ask the question until the end of the loop Very useful for password routines!

CW-V1 SDD 0909 LOOP 2 TYPE Do…Loop Until Example – Loop until the product is greater than 25 Attach this code to the click event of the form Private Sub Form_Click() Dim FirstNo As Integer Dim SecondNo As Integer Dim Product As Integer Do FirstNo = InputBox("Enter the First Number") SecondNo = InputBox("Enter the Second Number") Product = FirstNo * SecondNo Print "The Product of " & FirstNo; " And " & _ SecondNo & " Is " & Product Loop Until Product > 25 Print "Product is now over 25. Time to stop!" End Sub

CW-V1 SDD Do…Loop Until Flowchart Start End Input FirstNo Input SecondNo FirstNo * SecondNo Print Product Product > 25? Loop Test

CW-V1 SDD LOOP 3 TYPE For…Next Loop The loop will execute a specified number of times – so you can set how many times you want the program to repeat EG 3 FOR A PASSWORD SYSTEM Controlled by a counter that increments each time the loop executes Change the increments on the counter by using the step keyword

CW-V1 SDD LOOP 3 TYPE For…Next Code & Flowchart Attach this code to the load event of a form Sub frmPrinter_load Dim i As Integer For i = 65 To 90 Print i; Tab; Chr(i) Next i Dim i as Integer For i = 1 to 100 Step 2 Print i Next i Start End Print counter value Print letter Max counter value reached? i is the counter which counts how many times the loop has run

CW-V1 SDD Activity 3 – Apply your learning - 25 mins Using SDD 100 create loop programs Complete tasks 1& 2 Early finishers to try task 3&4 Be prepared to answer questions on all the loops in SDD 100 All to try out tasks 3&4 as homework The ultimate is to complete tasks 5 & 6

CW-V1 SDD What have you learned today? Described loops and their uses Described various types of loop Created short programs which incorporate loops Explained to others code used to create loops Explained design methods used to design any program Applied learning to various scenarios (loop programs) Judged which loops to use in various scenarios Now task 4 a