Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution.

Slides:



Advertisements
Similar presentations
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
Advertisements

Mark Dixon, SoCCE SOFT 131Page 1 22 – Object Oriented Analysis, Design, and Programming.
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
Mark Dixon Page 1 22 – Object Oriented Programming in ASP.
Mark Dixon Page 1 05 – Constants and Variables. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 mins short answer (5 - 6 words.
Mark Dixon, SoCCE SOFT 136Page 1 05 – Conditional Execution.
Mark Dixon Page 1 05 – Conditional Execution. Mark Dixon Page 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6.
Mark Dixon, SoCCE SOFT 136Page 1 11 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon Page 1 13 – Coursework 2 Debrief: Spanish Words.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –Revise Variables and Conditional execution.
Mark Dixon, SoCCE SOFT 131Page 1 10 – Enumerated Data Types & Procedure Parameters.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Coursework 2 Debrief: Numbers Game.
Mark Dixon, SoCCE SOFT 131Page 1 06 – Iteration. Mark Dixon, SoCCE SOFT 131Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Procedure Parameters.
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 08 – Iterative Execution.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Conditional Execution.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon, SoCCE SOFT 131Page 1 10 – User Defined Functions.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Constants and Variables.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Conditional Execution.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Enumerated Data-Types & Pass-by-reference.
Mark Dixon, SoCCE SOFT 131Page 1 13 – Control Arrays & Container Controls.
Mark Dixon, SoCCE SOFT 136Page 1 06 – Information Processing: Data-types, Constants, Variables.
Mark Dixon Page 1 In-class Test Results Student Number Score (max 50) Classification is for guidance only Please feel free to come and discuss your results.
Mark Dixon, SoCCE SOFT 131Page 1 09 – User Defined Procedures: Scope, and Parameters.
Mark Dixon, SoCCE SOFT 131Page 1 11 – Arrays of Structures & Modules.
10 ThinkOfANumber program1July ThinkOfANumber program CE : Fundamental Programming Techniques.
Mark Dixon Page 1 22 – Coursework 2 Debrief: Phonics.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Information Processing: Data-types, Variables, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 7 – Procedures. Mark Dixon, SoCCE SOFT 131Page 2 Coursework 1 (Test) - Results Student Number Score (max 50) Classification.
Mark Dixon Page 1 10 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of code to declare a variable called h Write a line of.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon 1 07 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Mark Dixon Page 1 09 – Arrays. Mark Dixon Page 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon, SoCCE SOFT 136Page 1 9 – Procedures. Mark Dixon, SoCCE SOFT 136Page 2 Session Aims & Objectives Aims –To introduce the main concepts involved.
Mark Dixon 1 05 – Conditional Execution. Mark Dixon 2 Admin: Test (next week) In class test –teaching week 6 50 minutes short answer (5 - 6 words) currently.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon 1 11 – Array Variables. Mark Dixon 2 Questions: Loops What is the value of t, after this code executes? t = 0 For x = 4 To 6 t = t + x Next.
Mark Dixon Page 1 10 – Array Variables. Mark Dixon Page 2 C1 – In-class test Results mixed: –quite a few fails 34% (13/38) –some very good (91% max) ask.
Mark Dixon 1 08 – Variables. Mark Dixon 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40) What will.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
Mark Dixon, SoCCE SOFT 131Page 1 05 – Variables. Mark Dixon, SoCCE SOFT 131Page 2 Admin: Test (next week) In class test –teaching week 6 –university week.
Mark Dixon Page 1 03 – Dynamic HTML (client-side scripting)
Mark Dixon, SoCCE SOFT 131Page 1 24 – Datatypes and Object Association.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon, SoCCE SOFT 131Page 1 02 – Dynamic HTML (client-side scripting)
Mark Dixon Page 1 04 – Information Processing: Expressions, Operators & Functions.
Mark Dixon 1 9 – Case Study. Mark Dixon 2 Session Aims and Objectives Aims –To give an overview of the development of a web-page from initial idea to.
Mark Dixon, SoCCE SOFT 131Page 1 18 – Enumerated Data Types and Arrays of Structures.
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon Page 1 08 – Variables. Mark Dixon Page 2 Questions: Conditional Execution What is the result of (txtFah.value is 50): (txtFah.value >= 40)
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
Mark Dixon Page 1 15 – Structured Programming. Mark Dixon Page 2 Admin: Coursework 3 – Test In class test –9 Feb 2010 –2 Feb 2010: revision (technique)
Mark Dixon Page 1 04 – Conditional Execution. Mark Dixon Page 2 Questions: Expressions a)What is the result of: 10 * Int( ) b)How many functions.
Mark Dixon, SoCCE SOFT 131Page 1 17 – Procedures.
Mark Dixon 1 15 – Structured Programming. Mark Dixon 2 Admin: Test 2 In class test –11 Feb 2014 –4 Feb 2014: revision (technique) session 50 mins short.
Mark Dixon 1 13 – Parameters. Mark Dixon 2 Question: Arrays How many array variables are in the following code: Dim x Dim y Dim f(4) x = 12 y = 6 f(2)
Mark Dixon Page 1 09 – Iterative Execution. Mark Dixon Page 2 Questions: Variables Write a line of VBScript code to declare a variable called h Write.
15 – Structured Programming
17 – Modular Design in ASP.
6 – Iterative Execution.
Think What will be the output?
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
08 – Iterative Execution.
Software Development Techniques
CMPT 120 Lecture 4 – Unit 1 – Chatbots
Presentation transcript:

Mark Dixon, SoCCE SOFT 131Page 1 07 – Iterative Execution

Mark Dixon, SoCCE SOFT 131Page 2 Coursework 1 (Test) - Results Student Number Score (max 50) Classification is for guidance only Please feel free to come and discuss your results with me

Mark Dixon, SoCCE SOFT 131Page 3 Coursework 1 (Test) - Debrief Range of marks normal Failure rate quite high – 30% (3 / 10) –not unusual for this module –recoverable if corrective action is taken Please feel free to discuss marks in tutorial

Mark Dixon, SoCCE SOFT 131Page 4 Coursework 1 (Test) - Problems Answer question: –Name a variable: Dim x  x Conditional expressions: x > 4 –used in conditional statements: If picMain.height < 0 Then Parameters – data given to functions: x = Int(34.56) sqr(b)

Mark Dixon, SoCCE SOFT 131Page 5 Session Aims & Objectives Aims –To introduce the main concepts involved in getting the machine to perform repetitive tasks. Objectives, by end of this week’s sessions, you should be able to: –To be able to implement code that does repetitive tasks, using looping structures: known limits (for loop) unknown limits (do loop)

Mark Dixon, SoCCE SOFT 131Page 6 Example: Hello v0 Hello Option Explicit Sub btnHello_OnClick() lblHello.innerHTML = lblHello.innerHTML & "Hello " End Sub 1 user click: 1 Hello (1 line of code)

Mark Dixon, SoCCE SOFT 131Page 7 Example: Hello v1 Option Explicit Sub btnHello_OnClick() lblHello.innerHTML = lblHello.innerHTML & "Hello " End Sub 1 user click: 10 Hellos (10 lines of code) Lots of lines imagine 300 Hellos

Mark Dixon, SoCCE SOFT 131Page 8 Example: Hello v2 Option Explicit Sub btnHello_OnClick() Dim h For h = 1 to 10 lblHello.innerHTML = lblHello.innerHTML & "Hello " Next End Sub 1 user click: 10 Hellos (4 lines of code)

Mark Dixon, SoCCE SOFT 131Page 9 For... Next statement repeat code known number of times –reduces length of code –easier to change Syntax: For variable = start To end statementblock Next

Mark Dixon, SoCCE SOFT 131Page 10 Advantages Less code: This makes program: –Easier to read –Easier to change (imagine 500 Hellos) Option Explicit Sub btnGo_OnClick() Dim h For h = 1 To 10 lblHello.innerHTML = lblHello.innerHTML & "Hello " Next End Sub Option Explicit Sub btnGo_OnClick() lblHello.innerHTML = lblHello.innerHTML & "Hello " End Sub Hello v1Hello v2 10 lines 4 lines

Mark Dixon, SoCCE SOFT 131Page 11 Real Power of loops –using counter variable –do something slightly different each time Example: Dim num Dim tot tot = 0 For num = 1 To 5 tot = tot + num Next lblRes.InnerText = tot Example: Total

Mark Dixon, SoCCE SOFT 131Page 12 Example: Total

Mark Dixon, SoCCE SOFT 131Page 13 Question: For … Next What does the following code produce: Dim counter For counter = 1 To 10 lblNums.InnerText = lblNums.InnerText & counter Next What does the following code produce: Dim i For i = 24 To 8 Step -2 lblNums.InnerText = lblNums.InnerText & i & i * 2 Next

Mark Dixon, SoCCE SOFT 131Page 14 Example: Letter Count Option Explicit Sub btnCount_OnClick() Dim pos Dim count Dim char count = 0 For pos = 1 To Len(txtWords.value) char = Mid(txtWords.value, pos, 1) If char = "e" Then count = count + 1 End If Next lblCount.innerText = count End Sub

Mark Dixon, SoCCE SOFT 131Page 15 Example: Shades Option Explicit Sub btnShow_OnClick() Const stTag = "<span style=""background: #" Dim h, p, msg, red msg = txtMsg.value h = "" red = 255 For p = 1 To Len(msg) h = h + stTag + Hex(red) + "0000"">" h = h + Mid(msg, p, 1) h = h + " " red = red - 5 Next divTones.innerHTML = h End Sub

Mark Dixon, SoCCE SOFT 131Page 16 Do... Loop statement repeat code unknown number of times –more flexible than For –slower than For Syntax: Do [{While|Until} condition] [statementblock] Loop

Mark Dixon, SoCCE SOFT 131Page 17 Example: Do … Loop Can do everything a For … Loop can: Dim IDim i i = 1 Do While i <= 10For i = 1 To 10 lblN.InnerText = i picN.InnerText = i i = i + 1 LoopNext And more: Dim i i = 1 Do While i < 10 lblN.innertext = i If (i / 2) = Int(i / 2) then i = i + 1 Else i = i + 3 End If Loop

Mark Dixon, SoCCE SOFT 131Page 18 Question: Do … Loop What does the following produce: Dim num num = 20 Do While num > -12 lblDo.InnerText = lblDo.InnerText & num num = num Loop What does the following produce: Dim num num = 6 Do Until num > 4 num = num + 5 lblDo.InnerText = lblDo.InnerText & num Loop

Mark Dixon, SoCCE SOFT 131Page 19 Tutorial Exercise: Hello Task 1: Get the Hello Example (from the lecture) working. Task 2: Modify your page so that it uses a variable to temporarily build to html. Task 3: Modify your page so that the user can control how many 'Hellos' appear.

Mark Dixon, SoCCE SOFT 131Page 20 Tutorial Exercise: Letter Count Task 1: Get the Letter Count Example (from the lecture) working. Task 2: Modify your Letter Count page, so that the user can control which letter is counted. Hint: You will need a text box for the user to type a letter into. Task 3: Modify your Letter Count program, so that the user cannot type more than one letter in the letter text box. Hint: Use the text box’s change event, and the len function.

Mark Dixon, SoCCE SOFT 131Page 21 Tutorial Exercise: Vowel Count Task 1: Create a new page that counts the number of vowels (a, e, i, o, u) in a piece of text. Hint: similar to the letter count example.

Mark Dixon, SoCCE SOFT 131Page 22 Tutorial Exercise: Shades Task 1: Get the shades example from the lecture working. Task 2: Modify the page so that it puts a space in between each letter. Task 3: Change the program so that it uses shades of another colour instead. Task 4: Create a new page that selects random shades of your selected colour. Hint: use the Rnd function.

Mark Dixon, SoCCE SOFT 131Page 23 Tutorial Exercise: Chess Board Task 1: Use one for loop inside another to create a chess board.