Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CW-V1 SDD 0901 Principals of Software Design and Development Loops Starter: Water JugsWater Jugs."— Presentation transcript:

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

2 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

3 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

4 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

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

6 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 1 - 10”) Print UserNumber Do While UserNumber < 10 UserNumber = UserNumber + 1 Print UserNumber Loop

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

8 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!

9 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

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

11 CW-V1 SDD 09011 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

12 CW-V1 SDD 09012 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

13 CW-V1 SDD 09013 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

14 CW-V1 SDD 09014 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


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

Similar presentations


Ads by Google