National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
CS0004: Introduction to Programming Repetition – Do Loops.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
James Tam Repetition In Pascal In this section of notes you will learn how to rerun parts of your program without having to duplicate the code.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Chapter 5: Loops and Files.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Chapter 5: Control Structures II (Repetition)
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved For Loops October 16, 2013 Slides by Evan Gallagher.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
COIT29222 Structured Programming Slide 1 COIT29222-Structured Programming Lecture Week 06  Reading: Study Guide Book 2, Modules 9 & 10 Textbook (4 th.
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.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
1 Loops. 2 Topics The while Loop Program Versatility Sentinel Values and Priming Reads Checking User Input Using a while Loop Counter-Controlled (Definite)
‘Tirgul’ # 3 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #3.
 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.
6/3/2016 CSI Chapter 02 1 Introduction of Flow of Control There are times when you need to vary the way your program executes based on given input.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
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.
CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Loops and Files. 5.1 The Increment and Decrement Operators.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5: Looping.
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
Working with Loops, Conditional Statements, and Arrays.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
© The McGraw-Hill Companies, 2006 Chapter 3 Iteration.
Fundamental Programming Fundamental Programming More on Repetition.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
Controlling Program Flow with Looping Structures
Week 6 - Monday.  What did we talk about last time?  while loop examples  Lab 5.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
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.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chapter Looping 5. The Increment and Decrement Operators 5.1.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Selection Using IF THEN ELSE CASE Introducing Loops.
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.
Chapter 5: Loops Tarik Booker CS 201 California State University, Los Angeles.
CE En 270 Brigham Young University Norm Jones
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. 4 Simple Flow of Control.
Advanced Excel Topics – Loops
Introduction To Repetition The for loop
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Scratch: iteration / repetition / loops
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.
Do … Loop Until (condition is true)
Chapter 6: Repetition Statements
The structure of programming
Instructor: Craig Duckett
Prepared By: Deborah Becker
GCSE Computing:: While Loops
The while Looping Structure
Software Development Techniques
How to allow the program to know when to stop a loop.
Looping and Repetition
Presentation transcript:

National Diploma Unit 4 Introduction to Software Development Data Structures – Loops and selection

Data Processing Once data is entered we need to do something with it – this is data processing Most programming you will do has been done many times before by others – there is no need to ‘reinvent the wheel’ You can use some standard ‘structures’ to do common tasks

How a program runs Each variable has its own space reserved in memory once it is declared – Dim intcapacity as Integer We give this variable a value by initialising – intcapacity = The next lines in the program are then read and executed one line at a time

Common statements Using common, pre-formatted statements which perform set actions save us from having to design programs ‘from scratch’ Today we will look at: Conditional statements – what we do depends on what the situation is Using loops – to repeat actions over and over until we ask VB to stop

Conditional statements Use these when you want the program to make a choice based on data it gets if age is over 17 issue driving license The syntax in VB is: If Condition Then Line of code to process data End If - don’t forget to end your If!

Further conditions We can add another condition to give us 2 or more choices – an else statement If condition Then Line of code which does something Else Another line which executes if the first condition is false End If

Select case statements We could use a whole bank of ifs and elses to sort out complex data processing – but this would be confusing and messy! It’s much better to use the Select Case statement instead

Select case statements The syntax for select case is: Select Case variable Case first possibility Line of code to execute Case second possibility Line of code to execute instead End Select

Loop structures Use these when you want a line of code to be executed many times How many times depends on: Whether set conditions are met OR You can set a fixed number of times Loops are very versatile – get to know them and they will save you time

For…..Next loops Use this if you want to run a loop a fixed number of times It needs a variable to use as a counter to track the number of repeats Syntax of For…Next is: For first value To last value Line of code to execute Next value

Do …..while loops If you don’t know in advance how many times the loop will have to run, use a Do…While loop Be careful that you don’t create an infinite loop – it will run forever and crash your PC!

Do….While loop structure The syntax for do…while loop is: Do While value = whatever Line of code to execute Loop Or, alternatively While value = whatever Line of code to execute Wend

Writing Loops It’s important to get your code looking tidy so that you – and others can read it easily It will also make errors easier to spot Use indentation for this After the loop body begins press Tab to make the loop body inset At the last line remove the Tab

Example of good layout For Count = 1 to 10 Age = Age + 1 Form.Print “Age is ”; Age Next Count