Objectives After studying this chapter, you should be able to:

Slides:



Advertisements
Similar presentations
Programming with Microsoft Visual Basic th Edition
Advertisements

1.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Programming with Microsoft Visual Basic th Edition
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 9 Decisions, Decisions, Decisions.
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Chapter Four The Selection Structure
Microsoft Visual Basic 2008: Reloaded Fourth Edition
Chapter 4: The Selection Structure
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Decision Structures and Boolean Logic
Using the selection structure (Unit 7) Visual Basic for Applications.
Chapter 4: The Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Chapter 4: The Selection Structure
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
Chapter 4: Making Decisions. Understanding Logic-Planning Tools and Decision Making Pseudocode – A tool that helps programmers plan a program’s logic.
Microsoft Visual Basic 2008: Reloaded Third Edition Chapter Five More on the Selection Structure.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 4 Decision.
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Chapter 5: More on the Selection Structure
Programming with Microsoft Visual Basic th Edition
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Chapter Four The Selection Structure Programming with Microsoft Visual Basic th Edition.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Computer Programming TCP1224 Chapter 5 The Selection Structure.
Chapter 15 I’m on the Inside; You’re on the Outside (Nested Loops) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Tutorial 4: The Selection Structure 1 Tutorial 4 The Selection Structure.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Chapter Five More on the Selection Structure Programming with Microsoft Visual Basic th Edition.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
Random Functions Selection Structure Comparison Operators Logical Operator
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Exam 1 Review Jeff has 100 students in his MIS120 class. He is giving a 50 question exam worth 100 points. The following commands are available to you.
Microsoft Visual Basic 2008: Reloaded Third Edition
Java Programming Fifth Edition
Chapter 4: Decisions and Conditions
More on the Selection Structure
The Selection Structure
Chapter 4: The Selection Structure
Topics The if Statement The if-else Statement Comparing Strings
Programming with Microsoft Visual Basic 2008 Fourth Edition
An Introduction to Programming with C++ Fifth Edition
Microsoft Visual Basic 2005 BASICS
Making Decisions in a Program
Topics The if Statement The if-else Statement Comparing Strings
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 3: Introduction to Problem Solving and Control Statements
CIS16 Application Development Programming with Visual Basic
3 Control Statements:.
CIS 16 Application Development Programming with Visual Basic
Chapter 8: More on the Repetition Structure
Introduction to Problem Solving and Control Statements
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Chapter 3: Selection Structures: Making Decisions
The Selection Structure
Chapter 5: The Selection Structure
Presentation transcript:

Objectives After studying this chapter, you should be able to: Include the selection structure in pseudocode and in a flowchart Explain the difference between single-alternative and dual-alternative selection structures Code a selection structure using the If…Then…Else statement Include comparison and logical operators in a selection structure’s condition Prevent the division by zero run time error Swap two values Create a block-level variable

CIS 16 Application Development Programming with Visual Basic Chapter Four The Selection Structure

Selection structures All of the procedures in an application are written using 1 of 3 structures Sequence Instructions are processed sequentially Selection Instructions are dependent on a decision being made Repetition Instructions repeat until stopped

The Selection Structure The Selection Structure - also called the decision structure – indicates that a decision needs to me made before the program continues The decision is based on a condition that must be evaluated to determine the next instruction to process The condition must evaluate to either True or False only

The Selection Structure Three types of selection structures A single-alternative selection structure has a specific set of instructions to follow only when its condition evaluates to True A dual-alternative selection structure has one set of instructions to follow when the condition evaluates to True, but a different set of instructions to follow when the condition evaluates to False A multiple-alternative selection structure has many sets of instructions to follow based on conditions evaluating to True or False

Flowcharting a Selection Structure Decision symbol Used to represent the condition (decision) in both the selection and repetition structures Other symbols: Oval: Start/stop symbol Rectangle: Process symbol Parallelogram: Input/output symbol

Selection Structures

Coding Single-Alternative and Dual-Alternative Selection Structures STATEMENT BLOCK

Selection Structure (cont.) To determine whether a procedure requires a selection structure, and which one, study the problem specification Selection structure is: a) Sequence b) Dual c)not needed ?

Lets try flowcharting it

The Selection Structure (cont’d.)

Lets try flowcharting it

The Selection Structure (cont’d.)

NESTED SELECTION STRUCTURES

Nested Selection Structures When a decision needs to be made within a decision The inner selection structure is referred to as a nested selection structure. It is contained (nested) entirely within the outer selection structure.

Nested Selection Structures

Nested Selection Structures

MULTIPLE ALTERNATIVE SELECTION STRUCTURES

Multiple-Alternative Selection Structures Multiple-alternative selection structures or extended selection structures choose from several different alternatives.

Multiple-Alternative Selection Structures

Multiple-Alternative Selection Structures

Multiple-Alternative Selection Structures

Select Case Statement Select Case statement is simple and clear to code multiple selection structures.

Select Case Statement Specifying a Range of Values in a Case Clause

How to make comparisons

Comparison Operators Each comparison operator (also referred to as relational operators) can be used to compare two values, and the comparison always results in a Boolean value: either True or False. Rules for comparison operators: They do not have an order of precedence They are evaluated from left to right They are evaluated after any arithmetic operators in the expression

Comparison Operators (cont’d.)

Comparing Strings Visual Basic is case-sensitive, which means that the uppercase letters of the alphabet are not equal to their lowercase counterparts These three string comparisons will evaluate to False: "A" = "a", "Yes" = "yes", and "Yes" = "YES". Use the ToUpper method to temporarily convert a string to uppercase Use the ToLower method to temporarily convert a string to lowercase A text box’s CharacterCasing property indicates whether the text inside the control should remain as typed, or be converted to either uppercase or lowercase

Comparing Strings

Comparing Boolean Values Check boxes provide one or more independent and nonexclusive items from which the user can choose An interface can contain any number of check boxes, and any number of them can be selected at the same time Each check box should be labeled to make its purpose obvious

Comparing Boolean Values

Logical Operators Logical operators allow you to combine two or more sub-conditions into one compound condition The compound condition will always evaluate to a Boolean value: either True or False

Using Logical Operators When more than one condition is included in an If...Then...Else statement, the conditions are called a compound condition

Using the And Logical Operator

Using the Or Logical Operator

Using the Not Logical Operator

Logical Operators (cont’d.)

Logical Operators (cont’d.)

Microsoft Visual Basic 2012: Reloaded, Fifth Edition CHAPTER APPLICATION