Chapter 51 Select Case block A decision-making structure that simplifies choosing among several actions. Avoids complex nested If constructs. If blocks.

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

Chapter 4 Decision Making Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E. Reingold.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 51 ElseIf clause If condition1 Then action1 ElseIf condition2 Then action2 ElseIf condition3 Then action3 Else action4 End If.
1 CS 106, Winter 2009 Class 10, Section 4 Slides by: Dr. Cynthia A. Brown, Instructor section 4: Dr. Herbert G. Mayer,
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.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Chapter 5 - VB.Net by Schneider
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 4 - VB.Net by Schneider1 Chapter 4 General Procedures 4.1 Sub Procedures, Part I 4.2 Sub Procedures, Part II 4.3 Function Procedures 4.4 Modular.
ISBN Chapter 8 Statement-Level Control Structures.
Chapter 41 Sub Procedures, Part II (Continue). Chapter 42 Local Variable A variable declared inside a Sub procedure with a Dim statement Space reserved.
Chapter 5 - Visual Basic Schneider1 Chapter 5 Decisions.
Chapter 41 Function Procedures (Continue I). Chapter 42 Lab Sheet 4.7: Code Private Sub btnCalculate_Click(...) _ Handles btnCalculate.Click Dim a, b.
Chapter 31 Fundamentals of Programming in VB(Continue I) Numbers Arithmetic Operations Variables Incrementing the Value of a Variable.
Chapter 71 Using Part of an Array Sometimes we do not know how many elements will be needed in an array. We can declare a large array, say of 100 elements,
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
T ODAY ’ S Q UOTE "The computers do what you tell them to do, not what you want them to do. " ( Alexander Atanasov)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 4 Decision Structures and Boolean Logic.
Decision Structures and Boolean Logic
Review for Exam 2 School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 10, Friday 3/21/2003) - IF Blocks - Do Loops - Select.
Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks.
Lecture Set 5 Control Structures Part A - Decisions Structures.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 2 Section 5 Multiplying Integers. Multiplying Two Integers with Different Signs Words: The product of two integers with different signs. Numbers:
Chapter 5 - VB 2005 by Schneider1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks.
MIS 216 Exam1 Review Spring What to expect Questions like those on the home works and on the quizzes Evaluate code Create code Multiple choice and.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Copyright 2003 Scott/Jones Publishing Making Decisions.
CSC115 Introduction to Computer Programming Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA 19383
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 5: Making Decisions. Objectives Plan decision-making logic Make decisions with the if and if…else structures Use multiple statements in if and.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks 4.4 Input via User Selection.
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Condition – any expression that evaluates to true/false value Relational operators are BINARY.
Chapter 4 - VB 2008 by Schneider1 Chapter 4 – Decisions 4.1 Relational and Logical Operators 4.2 If Blocks 4.3 Select Case Blocks.
1 Chapter 5 – Decisions 5.1 Relational and Logical Operators 5.2 If Blocks 5.3 Select Case Blocks 5.4 A Case Study: Weekly Payroll.
Week 4 Relational and Logical Operators Dr. Jennifer Cunningham.
Select Case Blocks School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 8, Monday 3/03/2003)
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
CS0004: Introduction to Programming
5.04 Apply Decision Making Structures
Sequence, Selection, Iteration The IF Statement
Chapter 4 - VB 2008 by Schneider
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
The Selection Structure
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4: Making Decisions.
CSC115 Introduction to Computer Programming
Chapter 4 – Decisions 4.1 Relational and Logical Operators
Topics The if Statement The if-else Statement Comparing Strings
Control Structures: Selection Statement
Chapter 5 - Visual Basic Schneider
Visual Basic – Decision Statements
Chapter 5 Decisions.
Control Structures: Selection Statement
Controlling Program Flow
Control Structures.
Presentation transcript:

Chapter 51 Select Case block A decision-making structure that simplifies choosing among several actions. Avoids complex nested If constructs. If blocks make decisions based on the truth value of a condition; Select Case choices are determined by the value of an expression called a selector.

Chapter 52 Select Case Terminology Each of the possible actions is preceded by a clause of the form Case valueList where valueList itemizes the values of the selector for which the action should be taken.

Chapter 53 Lab Sheet 5.6: Form txtPosition txtOutcome

Chapter 54 Lab Sheet 5.6: Code Private Sub btnEvaluate_Click(...) _ Handles btnEvaluate.Click Dim position As Integer = CInt(txtPosition.Text) Select Case position Case 1 txtOutcome.Text = "Win" Case 2 txtOutcome.Text = "Place" Case 3 txtOutcome.Text = "Show" Case 4, 5 txtOutcome.Text = "You almost placed in the money." Case Else txtBox.Text = "Out of the money." End Select End Sub Selector Value Lists

Chapter 55 Lab Sheet 5.6: Output

Chapter 56 Lab Sheet 5.6: Code Private Sub btnEvaluate_Click(...) _ Handles btnEvaluate.Click Dim position As Integer = CInt(txtPosition.Text) Select Case position Case 1 To 3 txtOutcome.Text = "In the money. Congratulations" Case Is >= 4 txtOutcome.Text = "Not in the money." End Select End Sub

Chapter 57 Lab Sheet 5.6: Output

Chapter 58 Select Case Syntax The general form of the Select Case block is Select Case selector Case valueList1 action1 Case valueList2 action2 Case Else action of last resort End Select

Chapter 59 Rules for Select Case Case Else (and its action) is optional Each value list contains one or more of the following types of items separated by commas: 1.a literal; 2.a variable; 3.an expression; 4.an inequality sign preceded by Is and followed by a literal, variable, or expression; 5.a range expressed in the form a To b, where a and b are literals, variables, or expressions.

Chapter 510 Flowchart for Select Case