Practical Programming COMP153-08S Lecture 6: Making Decisions Part II.

Slides:



Advertisements
Similar presentations
Operators and Expressions Operators are symbols that produce a result based on some rules. Examples: +, -, =, > and
Advertisements

Practical Programming COMP153-08S Lecture: Repetition Continued.
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: The Selection Structure Programming with Microsoft Visual Basic.NET, Second Edition.
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)
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
Class 9.1 Chapter 4 Sections: 4.1, 4.2, 4.3
Visual Basic: An Object Oriented Approach 3 – Making Objects Work.
1 Midterm Review COMP 102. Tips l Eat a light meal before the exam l NO electronic devices (including calculators, dictionaries, phones, pagers, etc.)
Chapter 4: Control Structures: Selection
1 MATERI PENDUKUNG OPERATOR Matakuliah: M0074/PROGRAMMING II Tahun: 2005 Versi: 1/0.
CSCI 130 Chapter 4 Statements, Expressions, and Operators.
Microsoft Visual Basic 2008: Reloaded Fourth Edition
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
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.
Chapter 4: The Selection Structure
Lecture Set 5 Control Structures Part A - Decisions Structures.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 8 Dental Payment Application Introducing CheckBox es and Message Dialogs.
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.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Practical Programming COMP153-06S Lecture 3: Making Decisions.
JavaScript, Fourth Edition
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
CIVIL AND GEOMATIC ENGINEERING FT Okyere. CIV 257- COMPUTER PROGRAMMING Lecture 3.
COMPUTER PROGRAMMING I 5.04 Apply Decision Making Structures.
CSCI 171 Presentation 3. Operators Instructs C to perform some operation Assignment = Mathematical Relational Logical.
Practical Programming COMP153-08S Lecture: Repetition.
These Guys? Wait, What? Really?  Branching is a fundamental part of programming  It means taking an action based on decision  The decision is dependent.
Tutorial 4: The Selection Structure 1 Tutorial 4 The Selection Structure.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
Computer Science Up Down Controls, Decisions and Random Numbers.
Practical Programming COMP153-08A Lecture 4:Strings & Formatting.
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
© 2016, Mike Murach & Associates, Inc.
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Chapter 4: The Selection Structure
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4: Decision Structures and Boolean Logic
Chapter 4: Making Decisions.
An Introduction to Programming with C++ Fifth Edition
Topics The if Statement The if-else Statement Comparing Strings
Chapter 3:Decision Structures
CSI 101 Elements of Computing Spring 2009
Chapter 4: Decision Structures and Boolean Logic
Selection Statements.
Microsoft Visual Basic 2005: Reloaded Second Edition
Conditional Logic Presentation Name Course Name
The System.exit() Method
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Final Revision sheet- term2
Chapter 4: Decision Structures and Boolean Logic
Final Revision sheet- term2
Lecture 9: JavaScript Syntax
The boolean type and boolean operators
Presentation transcript:

Practical Programming COMP153-08S Lecture 6: Making Decisions Part II

Programming So Far First: Controls, Properties, Events Second: Types and Arithmetic Third: Variables and some Input/Output Fourth: Strings & Formatting Fifth: If and selection components Today: Scope, Select Case, Complex If

Variable scope - inside

Outside = Global

Variable scope Lifetime of variable depends on where you put the declaration Local Variables –Declarations in event handlers –Exist only during event –Can only be used in that event handler Global Variables –Declaration outside handler –Exists for the lifetime of the program –Can be used anywhere – shared by handlers

Two handlers

Fruit prices

The Select Case statement Select Case expression Case value statements Case value statements Case Else statements End Select

Fruit prices Select Case ItemTextBox.Text Case “1” PriceLabel.Text = (Convert.ToInt32(WeightTextBox.Text)* 3.99).ToString Case “2” PriceLabel.Text = (Convert.ToInt32(WeightTextBox.Text) * 5.5).ToString Case “3” PriceLabel.Text = (Convert.ToInt32(WeightTextBox.Text) * 6.0).ToString Case Else MessageBox.Show(“Please Enter 1, 2 or 3”) End Select

Calculator (2) Select Case (TextBox3.Text) Case "+“ Label4.Text = (Convert.ToInt32(TextBox1.Text) + Convert.ToInt32(TextBox2.Text)).ToString Case "-" Label4.Text = (Convert.ToInt32(TextBox1.Text) - Convert.ToInt32(TextBox2.Text)).ToString Case “*” Label4.Text = (Convert.ToInt32(TextBox1.Text) * Convert.ToInt32(TextBox2.Text)).ToString Case “/” Label4.Text = (Convert.ToInt32(TextBox1.Text) / Convert.ToInt32(TextBox2.Text)).ToString Case Else Label4.Text = “You must use on of (*,+,-,/,^)” End Select

Case is clever Case 1, 3, 5 Case 1 To 10 Case 1 To 4, 7 To 9, 11, 13 Dim Number As Integer (filled in somehow) Select Case Number ' Evaluate Number. Case 1 To 5 ' Number between 1 and 5, inclusive. MessageBox.Show("Between 1 and 5") Case 6, 7, 8 ' Number between 6 and 8. MessageBox.Show("Between 6 and 8") Case 9 To 10 ' Number is 9 or 10. MessageBox.Show("Greater than 8") Case Else ' Other values. MessageBox.Show("Not between 1 and 10") End Select

Comparisons =Equal to <>Not equal to >Greater than <Less than >=Greater than or equal <=Less than or equal to

Select Case and Is Dim Age As Integer (filled in somehow) Select Case Age Case Is < 5 MessageBox.Show(“Pre-school") Case 5 To 12 MessageBox.Show(“Primary School") Case Is > 12 MessageBox.Show(“Secondary or higher") Case Else MessageBox.Show(“Should never happen") End Select

Logical Connectives AndIf both true then result true OrIf either true then result true NotIf false then result true (vv) XorIf one and only one true then result is true – if both true or false then result is false

Complex If If Price >= 50 And PocketMoney < 50 Then Misery = 10 If PocketMoney > Price Or Price = SalePrice Then Misery = 0 If Tea Xor Coffee Then Drink = True Short circuit operators AndElse OrElse

THE END of the lecture