ASP-5-1 ASP Control Structures Colorado Technical University IT420 Tim Peterson.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

Microsoft® Small Basic
5.04 Apply Decision Making Structures
COMPUTER PROGRAMMING I Understand Problem Solving Tools to Design Programming Solutions.
Objectives Using functions to organize PHP code
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Chapter 5: Repetition Statements. In this chapter, you will learn about: Basic loop structures while loops Interactive while loops for loops Loop programming.
CIS101 Introduction to Computing Week 12 Spring 2004.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
5.05 Apply Looping Structures
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Python quick start guide
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
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.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
CONTROLLING PROGRAM FLOW
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Decision Making with Control Structures and Statements (non-audio version) © Dr. David.
CPS120: Introduction to Computer Science Decision Making in Programs.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
CMP-MX21: Lecture 5 Repetitions Steve Hordley. Overview 1. Repetition using the do-while construct 2. Repetition using the while construct 3. Repetition.
1 Flow Control Ifs, loops. 2 Data Type At the lowest level, all data in a computer is written in 1’s and 0’s (binary) How the data gets interpreted, what.
JavaScript, Fourth Edition
CSCI 171 Presentation 5. The while loop Executes a block as long as the condition is true general form: while (condition) { statement 1; statement 2;
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
1 Scripting Languages VBScript - Recognized mainly by Internet Explorer only - Netscape does have a plug-in JavaScript - Recognized by Internet Explorer.
Using Loops. Goals Understand how to create while loops in JavaScript. Understand how to create do/while loops in JavaScript. Understand how to create.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Working with Loops, Conditional Statements, and Arrays.
Controlling Program Flow with Looping Structures
CSI 3125, Preliminaries, page 1 Control Statements.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Controlling Computers with Programs When you create a computer program you are creating a set of instructions that tell the computer exactly and completely.
Controlling Program Flow with Decision Structures.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Copyright © Don Kussee 1410-Ch5 #1031 CNS 1120 Chapter 5 Selection statements 1120-Ch5.PPT.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
JavaScript, Sixth Edition
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Structured Programming The Basics
Advanced Excel Topics – Loops
Visual Basic 6 (VB6) Data Types, And Operators
IF statements.
JavaScript Syntax and Semantics
Introduction To Flowcharting
Development of Internet Application 1501CT - Sara Almudauh
( Iteration / Repetition / Looping )
ITM 352 Flow-Control: Loops
Control Structures: Part 1
Case & Repetitive Statements
Class 4: Repetition Pretest Posttest Counting Flowchart these!
FLUENCY WITH INFORMATION TECNOLOGY
Prepared By: Deborah Becker
ASP control structure BRANCHING STATEMENTS
How to allow the program to know when to stop a loop.
Presentation transcript:

ASP-5-1 ASP Control Structures Colorado Technical University IT420 Tim Peterson

ASP-5-2 Definitions Flow - Order of execution of statements. Execution - Process of carrying out the instruction in a statement. Action Statement - Statements that perform an activity. Control Statement - Statements that provide instructions on which statements to execute. Code Structures - Several lines of a code that achieve a task. Control Structures - a set of statements that govern the order of execution.

ASP-5-3 Control Statements Three types of control statements exist: –Branching Structures - Perform a test If..Then..Else Select Case –Looping Controls - allow same block of code to run repetitively. For Next Do While –Jumping Controls - allows the programmer to pass execution to another block of code. Subprocedure Function

ASP-5-4 If Then Else If Then Else can consists of four parts: –An expression used to test for a true false answer –“if true” section of code –“if false” section of code –Ending statement

ASP-5-5 If Then Else Examples If Then Else can be built four different ways: –1st method - Used if you only have one statement to perform in case of a “true” test <% If varFaxConfirm = “Yes” then Response.Write “Please enter your fax number” %>

ASP-5-6 If Then Else Examples - Cont’d –2nd method - Used if you have more than one statement to execute in the case of a “true” test <% If varFaxConfirm =“Yes” Then Response.Write “Please click below and provide your fax number.” Response.Write “ Click here ” End If %>

ASP-5-7 If Then Else Examples - Cont’d –3rd method - Used if you want to perform one state in the case of a “true” and a “false” test. <% If varFaxConfirm =“Yes” Then Response.Write “Please enter your fax number.” Else Response.Write “No fax confirmation will be sent.” End If %>

ASP-5-8 If Then Else Examples - Cont’d –4th method - Used to continually nest statements using ElseIf <% If varConfirm = “Fax” then Response.Write “Please enter your fax number.” ElseIf varConfirm = “ ” then Response.Write “Please enter your address.” ElseIf varConfirm = “Voic ” then Response.Write “Please enter your voice mail number.” Else Response.Write “No confirmation will be sent.” End If %>

ASP-5-9 If Then Else Common Errors Devising a test that does not resolve to true or false Leaving out the End If Leaving out the Else Coding End If as EndIf Multiple tests can only be accomplished with the ElseIf.

ASP-5-10 Select Case Select Case consists of four parts: –State which variable to test –State a possible answer and what to do if the answer is a match –Repeat for all possible answers that are to be handled –End the Select Case Structure

ASP-5-11 Select Case Examples –1st example - This is the simplest method: <% Select Case varConfirmation Case “Fax” Response.Write “ Fax Case “Telephone” Response.Write “ Telephone Case “ ” Response.Write “ End Select %>

ASP-5-12 Select Case Examples - Cont’d –2nd example - Illustrates how to process data that does not match any selection criteria. <% Select Case varMonthPref Case “march” Response.Write “Your meeting will be held on March 15th “ Case “March” Response.Write “Your meeting will be held on March 15th “ Case “april” Response.Write “Your meeting will be held on April 16th “ Case “April” Response.Write “Your meeting will be held on April 16th “ Case Else Response.Write “your request for “ & varMonthPref Response.Write “is not recognized. Please click the back button on your browser “ Response.Write “and reset then re-enter the form data again. ” End Select %>

ASP-5-13 Select Case Examples - Cont’d 3rd Example - Multiple selection criteria can be used for one Case statement. <% Select Case varMonthPref Case “march”, “March”, “mar”, “Mar”, “MAR” Response.Write “Your meeting will be held on March 15th “ Case “april”, “April”, “apr”, “Apr”, “APR” Response.Write “Your meeting will be held on April 16th “ Case Else Response.Write “your request for “ & varMonthPref Response.Write “is not recognized. Please click the back button on your browser “ Response.Write “an reset then re-enter the form data again. ” End Select %>

ASP-5-14 Select Case Examples - Cont’d 4th Example - Lets fix the case problem. <% Select Case Lcase(varMonthPref) Case “march”, “mar” Response.Write “Your meeting will be held on March 15th “ Case “april”, “apr” Response.Write “Your meeting will be held on April 16th “ Case Else Response.Write “your request for “ & varMonthPref Response.Write “is not recognized. Please click the back button on your browser “ Response.Write “an reset then re-enter the form data again. ” End Select %>

ASP-5-15 Common Select Case Errors Putting more than one variable on the Select..Case line. Not making answers mutually exclusive. Not have a possible answer for each case line. Typing Select Case or End Select as one word. Finishing the structure with End Case instead of End Select

ASP-5-16 For Next For Next statement consists of three parts: –First line describes how many times to go through the loop. –2nd- A set of lines that define the action statements to carry out within the loop. –3rd - Final line indicates the end of the action statements and tells ASP to go back and start the loop over.

ASP-5-17 For Next Example ForNext One Response Weekly Client Contacts for George Washington <% varStart=CDate(Request.Form("start")) varEnd=CDate(Request.Form("end")) varNumberDays=(varEnd-varStart) For varLineCounter = 0 to varNumberDays Response.Write "Clients: ___________________" Response.Write " " Next %> signed _________________________ George Washington

ASP-5-18 Common For..Next Errors Leaving out the counter variable Forgetting “=“ or the “to” on the first line Leaving out the Next statement Forgetting the start or end number

ASP-5-19 For Each..Next This is used for array elements and ASP objects. <% Dim Item Dim strCities(1) strCities(0) = “Colorado Springs” strCities(1) = “Denver” For Each Item in strCities Response.Write Item & “ ” Next %>

ASP-5-20 Do While Example Do While Sales Calls for This Month <% varRowCount = 1 varTodayDate = day(now()) Do While varRowCount <= varTodayDate Response.Write "For ____________ " Response.Write "number of clients met was ______ " varRowCount = varRowCount + 1 Loop %>

ASP-5-21 Common Do..While Errors Using Next instead of Loop for closing statement Not changing the expression variable (infinite loops) Performing one too many or few cycles. Using for a test condition when = should have been used.

ASP-5-22 DO Loop..While This is a variation and forces the code to be executed once before an evaluation is accomplished: Do.. Place code here. Loop While varRowCount <= varTodayDate

ASP-5-23 Jumping Structures Allow you to reuse code. Subprocedures are used to carry out an action.e.g putting text on a page. Functions carry out action statements and return a result. Procedures require the following: –Name –Code in the body of the procedure –Ending statement

ASP-5-24 Subprocedure Examples Sub SalesContactInfo Response.Write “Price quotes can be obtained from” Response.Write “Tom at ” End Sub many lines about gears Call SalesContactInfo … many lines about bolts Call SalesContactInfo …

ASP-5-25 Functions Written similar to procedures 1st line of a function starts with “Function” Last line of a function is “End Function” Function usually receive a parameter –Function SimpleDollar(varMoney) The function name becomes the variable passed back out of the function “SimpleDollar” Functions are called by just typing its name –varMyMoney = SimpleDollar(BigMoney)