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.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Looping Structures: Do Loops
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
CS0004: Introduction to Programming Repetition – Do Loops.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Lecture Set 5 Control Structures Part A - Decisions Structures.
ENGR 112 Decision Structures.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
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.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
Algorithm Design.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
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.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Visual Basic Objects / Properties / Methods PropertyAdjective ObjectNoun Part of the application Attribute MethodVerb Action to do something.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
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.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
 Type Called bool  Bool has only two possible values: True and False.
Control Flow (Python) Dr. José M. Reyes Álamo.
Introduction to Programming Lecture 2
Chapter 3: Decisions and Loops
Visual Basic 6 (VB6) Data Types, And Operators
Sequence, Selection, Iteration The IF Statement
Chapter 3 Edited by JJ Shepherd
Programming Fundamentals
Chapter 4: Making Decisions.
Expressions and Control Flow in JavaScript
JavaScript: Control Statements.
Control Structures: Part 1
Topics The if Statement The if-else Statement Comparing Strings
Boolean Expressions and If statements
Chapter 8 JavaScript: Control Statements, Part 2
Objectives After studying this chapter, you should be able to:
Chapter (3) - Looping Questions.
3 Control Statements:.
Visual Basic – Decision Statements
Computer Science Core Concepts
VB Decisions & Conditions
2.6 The if/else Selection Structure
Visual Basic Programming
ASP control structure BRANCHING STATEMENTS
Chapter 8 JavaScript: Control Statements, Part 2
Presentation transcript:

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 two basic types are: If statements and Select Case statements

Slide 3 If statement v If statement: single line or multiple lines v Single line: (single task) –Syntax: If condition Then command If x > 5 then x = 0 v multiple lines: (multiple tasks) –Syntax: If condition Then Commands end if If x > 5 Then x = 0 End If If cDepositAmt > 0 Then cTotalPaid = cTotalPaid + cDepositAmt cDepositAmt = 0 Call UpdateReservation End If

Slide 4 If statement v Using NOT operator If Not bTaxable Then cSalesTax = 0 cUseTax = 0 End If v Else part If condition Then statements to process when condition is True Else statements to process when condition is False End If

Slide 5 If statement v ElseIf Part If fTest < 0 Then lblResult.Caption = “Negative” ElseIf fTest = 0 Then lblResult.Caption = “Zero” Else lblResult.Caption = “Positive” End If

Slide 6 Select Case v Allows to conditionally execute any of a series of statement groups based on the value of a test expression, which can be a single variable or a complex expression. v Syntax: Select Case testexpression [Case expressionlist-n statement group 1 [Case Else expressionlist-n statement group 2 End Select

Slide 7 Select Case nQtyOrdered = Val(txtQuantity) Select Case nQtyOrdered Case Is < 0 ‘note use of comparison MsgBox “Order quantity cannot be negative!”, vbExclamation Exit Sub Case 1, 2, 3 ‘note use of list fDiscount = 0 Case 4 To 9 ‘note use of range fDiscount = 0.03 Case 10 To 49 fDiscount = 0.08 Case Is > 50 fDiscount = 0.1 End Select

Slide 8 Select Case

Slide 9 Loops v Loops perform repetitive tasks in a program. v Three main types: –Counter loops (For): perform a task a set number of times –Conditional loops (Do): perform a task while a specified condition exists or until a specified condition exists. –Enumeration loops: used to perform an action on each item in a group of objects.

Slide 10 For Loops v Repeats a group of statements a specified number of times. v Define a counter variable v Start and end value v Step value (Optional) –For counter = start To end [Step step] [statements] [Exit For] [statements] Next Nested For Loop: For I = 1 To 10 For J = 1 To 10 For K = 1 To Next

Slide 11 For Loops v Example 1: For i = 1 To 10 sTemp = i & “ squared is “ & (i * i) Printer.Print sTemp Next i v Example 2: For i = 1 To 12 fMonthSales(i) = 0 fMonthExpenses(i) = 0 fMonthProfit(i) = 0 Next i

Slide 12 Do Loops v Repeats a block of statements while a condition is True or until a condition becomes True. v Syntax –Do [{While | Until} condition] [statements] [Exit Do] [statements] Loop –Do [statements] [Exit Do] [statements] Loop [{While | Until} condition]

Slide 13 Do Loops v Example 1: Dim I As Integer I = 0 Do I = InputBox(“Enter 0 to exit the loop!”) Loop Until I = 0

Slide 14 Logical Expressions v Relational operators are used to construct Logical Expressions. The standard operators are: =Equal to >Greater than <Less than <>Not equal to >=Greater than or Equal to <=Less than or Equal to v The comparison is based on the ASCII coding scheme where uppercase is less than lowercase; numbers are less than uppercase characters. v A condition is an expression. Like all expressions conditions are evaluated and return a value. v The return value of a logical expression is either True or False