Computer Programming Chapter 5: Switch statement

Slides:



Advertisements
Similar presentations
Control Structures.
Advertisements

If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
Programming In C++ Spring Semester 2013 Lecture 4 Programming In C++, Lecture 3 By Umer Rana.
1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Control Structures Nested ifs, switch statements.
Switch Statement. Nested IF-ELSE Statement if (month == 1) { mString="January"; } else if (month == 2) { mString=“February”; } else if (month == 3) {
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
True or false A variable of type char can hold the value 301. ( F )
(c) 2003 E.S.Boese1 Conditionals Chapter 10 - Student.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
true (any other value but zero) false (zero) expression Statement 2
1 Conditionals In many cases we want our program to make a decision about whether a piece of code should be executed or not, based on the truth of a condition.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
Selection. Computer Programming 2 Objectives Examine if statement in more detail Study use of switch statement to implement multialternative selections.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
CHAPTER 4: CONDITIONAL STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 8 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 9 – Income Tax Calculator Application: Introducing.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Multi Way Selection You can choose statement(s) to run from many sets of choices. There are two cases for this: (a)Multi way selection by nested IF structure.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
Chapter 05 (Part III) Control Statements: Part II.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
Module 3: Steering&Arrays #1 2000/01Scientific Computing in OOCourse code 3C59 Module 3: Algorithm steering elements If, elseif, else Switch and enumerated.
Conditions CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
General Computer Science for Engineers CISC 106 Lecture 2^4 Roger Craig Computer and Information Sciences 03/23/2009.
CPS120: Introduction to Computer Science Decision Making in Programs.
CSI 3125, Preliminaries, page 1 Control Statements.
COMP Loop Statements Yi Hong May 21, 2015.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
 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.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
CHAPTER 4 DECISIONS & LOOPS
Computer Programming Chapter 1: Introduction
Chapter 6 Conditionals.
Compound Condition Break , Continue Switch Statements in Java
Computer Programming Chapter 10: Array in Functions
Expressions and Control Flow in JavaScript
Chapter 8: Control Structures
Control Structures.
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Statement-Level Control Structures
The switch statement: an alternative to writing a lot of conditionals
Control Structures Part 3
Conditional Statements
By Hector M Lugo-Cordero September 3, 2008
Testing and Comparing Values
CHAPTER 4: Conditional Structures
PROGRAM FLOWCHART Selection Statements.
Decision making and control functions
Chap 7. Advanced Control Statements in Java
PHP CONDITIONAL STATEMENTS
Chapter 6 Conditionals.
Presentation transcript:

Computer Programming Chapter 5: Switch statement by Mohd Jamil Mohamed Mokhtarudin Faculty of Mechanical Engineering mohdjamil@ump.edu.my

Chapter Description Aims Expected Outcomes To construct C programming involving switch statement Expected Outcomes Know to construct conditional statement using C programming

Switch statement Still remember?? Not this switch. Switch statement has similar operation as electrical switch, which allows user ‘to choose’ either on or off.

Switch statement Still remember?? CAT PET ANIMAL CHICKEN FOOD LION DANGER

Example switch statement

Switch statement Basic structure: switch, case, break switch() {} – put your variable in the () case – switch will find the case that has similar value as the variable in () REMINDER: must put : after case! If the variable is equal with the case value, any statement following the case will be executed Break – allow the switch statement to exit

Switch statement default – executed when none of the case matches the variable Switch and if-else are almost similar – switch allows for more possibility of execution paths.

Conclusion of The Chapter Know how to use switch! Switch and if-else are almost the same…