ASP control structure BRANCHING STATEMENTS

Slides:



Advertisements
Similar presentations
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Advertisements

 Control structures  Algorithm & flowchart  If statements  While statements.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
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.
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
5.05 Apply Looping Structures
Invitation to Computer Science, Java Version, Second Edition.
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.
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.
CPS120 Introduction to Computer Science Iteration (Looping)
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
1 INF110 Visual Basic Programming AUBG Spring semester 2011 Reference books: Schneider D., An Introduction to Programming Using Visual Basic, Prentice.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
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.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
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.
Lab 4 Range Review, Control Logic and Loops ► Range Review ► Control Logic and Loops ► Exercise.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
ASP-5-1 ASP Control Structures Colorado Technical University IT420 Tim Peterson.
Introduction to Problem Solving and Control Statements.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
CPS120 Introduction to Computer Science Iteration (Looping)
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Controlling Program Flow with Decision Structures.
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.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
By “FlyingBono” 2009_02By FlyingBono.  ASP code is embedded in HTML using tags.  A ASP scripting block always starts with.  Server scripts are executed.
Recursion and Branching By: Engr. Faisal ur Rehman CE-105T Spring 2007 By: Engr. Faisal ur Rehman CE-105T Spring 2007.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
Introduction to Programming Lecture 2
UNIT 5 Lesson 15 Looping.
CHAPTER 4 REPETITION CONTROL STRUCTURE / LOOPING
Repetition Structures Chapter 9
Visual Basic 6 (VB6) Data Types, And Operators
CHAPTER 5 SERVER SIDE SCRIPTING
Problem Solving and Control Statements: Part 2
Control Structures: Part 2
Development of Internet Application 1501CT - Sara Almudauh
CiS 260: App Dev I Chapter 4: Control Structures II.
JavaScript: Control Statements.
ITM 352 Flow-Control: Loops
Arrays, For loop While loop Do while loop
Control Structures: Part 1
Introduction to Problem Solving and Control Statements
Fundamentals of visual basic
Computer Science Core Concepts
Control Structures Part 1
Case & Repetitive Statements
CMPE212 – Reminders The other four assignments are now posted.
Prepared By: Deborah Becker
PROGRAM FLOWCHART Iteration Statements.
Presentation transcript:

ASP control structure BRANCHING STATEMENTS Branching statements perform a test. They might check to see if x=2 or y=5 or if x>y. Based upon the results of the test, certain code is executed while other code is skipped. There are two types of branching statements we will run into: If--Then--Else is generally used to choose from one of two sets of lines to execute. EXAMPLE: If intFriends > 5 then      Response. Write "You have a lot of friends" Else      Response. Write "You need to be more social." End If As you can see from above, there are four parts to the If--Then statement. An expression that is either true or false An "if true" section An "if false" section (OPTIONAL) An ending statement

Branching Structure Basic If--Then Rules: Every expression tested will either evaluate to true or false You can only use one statement in the single line if--then If you use more than one line, you must use End If If you want action in the case of a false evaluation, you must use the else statement Once an expression evaluates to true, the If/Then structure is exited. Example

Select case SELECT CASE Although you can use the ElseIf statement to check multiple expressions, you should really use the Select Case branching control structure when that situation arises. Select Case strLanguage      Case "Spanish"           Response.Write "Ola"      Case "English"           Response.Write "Hello"      Case "French"           Response.Write "Bonjour"      Case "German"           Response.Write "Gutentag"      Case Else           Response.Write "Sorry.......We'd            love to say hello, but we don't            know how" End Select As you can see from above, there are four parts to the Select Case statement. State which variable should be tested, in this case strLanguage State a possible value and what to do when the variable evaluates to true. The possible value comes after "Case" Repeat as necessary End the Select Case structure using "End Select"

Select case Basic Select Case Rules: Use Select Case when there are more than two possibilities The first line states the variable to be evaluated Case lines give a value and a comparitor to check against. ASP will execute and exit after the first Case match. Example

For .. next For...Next Loop You can use a For...Next statement to run a block of code, when you know how many repetitions you want. You can use a counter variable that increases or decreases with each repetition of the loop, like this: For i=1 to 10 some code Next The For statement specifies the counter variable (i) and its start and end values. The Next statement increases the counter variable (i) by one.

For.. next Step Keyword Using the Step keyword, you can increase or decrease the counter variable by the value you specify. In the example below, the counter variable (i) is increased by two each time the loop repeats. For i=2 To 10 Step 2 some code Next To decrease the counter variable, you must use a negative Step value. You must specify an end value that is less than the start value. In the example below, the counter variable (i) is decreased by two each time the loop repeats. For i=10 To 2 Step -2

For each… Next A For Each...Next loop repeats a block of code for each item in a collection, or for each element of an array. dim cars(2) cars(0)="Volvo" cars(1)="Saab" cars(2)="BMW" For Each x in cars Response.write(x & "<br />") Next

While Wend While...Wend Statement Executes a series of statements as long as a given condition is True. While condition    Version [statements] Wend The following example illustrates use of the While...Wend statement: Dim Counter Counter = 0   ' Initialize variable. While Counter < 20   ' Test value of Counter.     Counter = Counter + 1   ' Increment Counter.   Alert Counter Wend   ' End While loop when Counter > 19.

Do While Do...Loop You can use Do...Loop statements to run a block of code when you do not know how many repetitions you want. The block of code is repeated while a condition is true or until a condition becomes true. Repeating Code While a Condition is True You use the While keyword to check a condition in a Do...Loop statement. Do While i>10 some code Loop If i equals 9, the code inside the loop above will never be executed.

Do.. until You use the Until keyword to check a condition in a Do...Loop statement. Do Until i=10 some code Loop If i equals 10, the code inside the loop will never be executed. Do Loop Until i=10 The code inside this loop will be executed at least one time, even if i is equal to 10.

Procedures One of the techniques used for effective programming is to divide a big assignment in (relatively small) sub-assignments. Each sub-assignment is meant to (possibly completely) solve a particular problem so that other sub-assignments of the program can simply request its result or refer to it when necessary. Such a sub-assignment is called a procedure. example

Functions Like a sub procedure, a function is used to perform an assignment. The main difference between a sub procedure and a function is that, after carrying its assignment, a function gives back a result. We also say that a function "returns a value". To distinguish both, there is a different syntax you use for a function.