BACS 287 Programming Fundamentals 3. BACS 287 Programming Fundamentals This lecture introduces the following decision control structure topics: – If-Then.

Slides:



Advertisements
Similar presentations
5.04 Apply Decision Making Structures
Advertisements

Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
BACS 287 Programming Fundamentals 2. BACS 287 Programming Fundamentals This lecture introduces the following topics: – Statements – Expressions – Operators.
Selection (decision) control structure Learning objective
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
Subject: Information Technology Grade: 10
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 6 Horstmann Programs that make decisions: the IF command.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
BACS 287 Programming Fundamentals 4. BACS 287 Programming Fundamentals This lecture introduces the following iteration control structure topics: – Do.
CSI 101 Elements of Computing Spring 2009 Lecture #5 Designing with Pseudocode Wednesday, February 4th, 2009.
1 CS 105 Lecture 5 Logical Operators; Switch Statement Wed, Feb 16, 2011, 5:11 pm.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
Solving Equations by Adding and Subtracting: Vocabulary Solve: To solve an equation mean to find a solution to the equation. Isolate the variable: Get.
OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME
Chapter 4 The If…Then Statement
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.
Oracle10g Developer: PL/SQL Programming1 Objectives Programming fundamentals The PL/SQL block Define and declare variables Initialize variables The NOT.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Selection Structure If... Then.. Else Case. Selection Structure Use to make a decision or comparison and then, based on the result of that decision or.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
1.4 Solving Equations ●A variable is a letter which represents an unknown number. Any letter can be used as a variable. ●An algebraic expression contains.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
BACS 287 Programming Logic 2. BACS 287 Sequence Construct The sequence construct is the default execution mode for the CPU. The instructions are executed.
Programming with Microsoft Visual Basic th Edition
Chapter 8 Decision Making Using the IF and EVALUATE Statements.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Access VBA Programming for Beginners - Class 4 - by Patrick Lasu
Lecture 7: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
VBScript Conditional Statements. Conditional Statements Very often when you write code, you want to perform different actions for different decisions.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Topics: Selection Statements. Processing Involving Selecting Instructions An instruction that allows deviation and selection to take place uses the ‘IF’
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
Controlling Program Flow with Decision Structures.
Sum of Arithmetic Sequences. Definitions Sequence Series.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
ME 142 Engineering Computation I Condition Statements.
Opener: Find three consecutive odd integers whose sum is -63 Integer #1 = n Integer #2 = n + 2 Integer #3 = n + 4 (n) + (n + 2) + (n + 4) = -63 3n + 6.
Slide 1 Chapter 4 The If…Then Statement  Conditional control structure, also called a decision structure  Executes a set of statements when a condition.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
 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.
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.
© 2006 Lawrenceville Press Slide 1 Chapter 5 The If…Then Statement (One-Way)  Conditional control structure, also called a decision structure  Executes.
Kondisi dan Perulangan
Kondisi dan Perulangan
5.04 Apply Decision Making Structures
Chapter 4 The If…Then Statement
OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME
Oracle11g: PL/SQL Programming Chapter 2 Basic PL/SQL Block Structures.
Chapter 5 Decisions. Chapter 5 Decisions ssential uestion: How are Boolean expressions or operators used in everyday life?
Factors, multiple, primes: Factors from prime factors
Control Structures: Part 1
Chapter 3: Introduction to Problem Solving and Control Statements
Solving Percent Problem with Equations
Conditional Logic Presentation Name Course Name
CS2011 Introduction to Programming I Selections (I)
Factors, multiple, primes: Multiples
PHP CONDITIONAL STATEMENTS
Presentation transcript:

BACS 287 Programming Fundamentals 3

BACS 287 Programming Fundamentals This lecture introduces the following decision control structure topics: – If-Then statements – IIf statements – If-Then-Else statements – Select Case statements

BACS 287 Decision Structures Visual Basic has 4 primary decision structures: – IF-Then – IIF – IF-Then-Else – Select Case These structures work basically the same as was covered in the pseudocode lectures.

BACS 287 If-Then Statements If-Then statements have 2 formats: 1) If condition Then statement 2) If condition Then statements End If

BACS 287 If-Then Examples If datDate = Date then Debug.Writeline “Today” If strColor = “red” then Debug.Writeline “Color = red” End If If shoX = 1 and shoY = 3 then shoZ = shoX + shoY Debug.Writeline “Sum is :”; shoZ End If

BACS 287 IIf Statements The IIF statement is intended to assign a True or False value anywhere a function could be used. result = IIF(condition, truevalue, falsevalue) The IIF does not allow multiple true/false statements. Everything must fit into a single expression.

BACS 287 IIf Examples IIf(intCnt >= 10,Debug.Writeline “over 10”,Debug.Writeline “under 10”) IIf(IsNull(strX), 0, strX.Length) Function Check (intTest as integer) Check = IIf(intTest> 100, “Large”, “Small”) End Function

BACS 287 If-Then-Else Statements The If-Then-Else structure allows the standard two branch IF statement to be defined. IF condition1 Then [statement block-1] Else [statement block-2] End If

BACS 287 If-Then-Else Example If intValue > 100 then intBigValueCnt += 1 Else intSmallValueCnt += 1 End If

BACS 287 If-Then-Else Statements The If-Then-Else structure also allows several statement blocks to be defined. IF condition1 Then [statement block-1] ElseIf condition2 Then [statement block-2]... Else [statement block-n] End If

BACS 287 If-Then-Else Example If decSales > then decComm = Calc_Com(.17) ElseIf decSales > then decComm = Calc_Com(.13) ElseIf decSales > then decComm = Calc_Com(.08) Else decComm = Calc_Com(.05) End If

BACS 287 Select Case Statements Select Case statements are the Visual Basic version of a CASE statement. Select Case test-expression [Case expression-list1 [statement block-1]] [Case expression-list2 [statement block-2]]... [Case Else [statement block-n]] End Select

BACS 287 Select Case Example Select Case strEmpStatus Case “full” strStatus = “Full Time” Case “part” strStatus = “Part Time” Case “contract” strStatus = “Contractor” Case Else strStatus = “Unknown” End Select

BACS 287 In-Class Selection Example 1 Use a selection structure to save a value of “senior” in the strClass variable when the value of the strYear variable is equal to “sr”, “junior” if it is equal to “j”, “sophomore” if it equals “so”, and “freshman” if it equals “f”. If strYear is any other value, strClass should be set to “error”.

BACS 287 In-Class Selection Answer 1 If strYear = “f” then strClass = “freshman” ElseIf strYear = “so” then strClass= “sophomore” ElseIf strYear = “j” then strClass = “junior” ElseIf strYear = “sr” then strClass = “senior” Else strClass = “error” End If Select Case strYear Case “f” strClass = “freshman” Case “so” strClass = “sophomore” Case “j” strClass = “junior” Case “sr” strClass = “senior” Case Else strClass = “error” End Select

In-Class Selection Example 2: Translate to a Selection Statement

In-Class Selection Answer 2 If Q1 = 5 then If Q2 = 4 then ST1 = “a” ST2 = “b” Else ST7 = “g” End If Else ST3 = “c” If Q3 = 1 then ST4 = “d” End If ST5 = “e” End If ST6 = “f”