1 st Semester 2005 1 Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.

Slides:



Advertisements
Similar presentations
1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem
Advertisements

Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Selection Statement – Selection Statement Modified from Aj. Thanachat Thanomkulabut’s slide 1 st semester, 2012.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
DECISION MAKING STRUCTURES Computer Programming 2.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
If Statements & Relational Operators Programming.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
true (any other value but zero) false (zero) expression Statement 2
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
Branch Statements (Decision). Flow of Control  The order in which a program performs actions.  A branching statement chooses one of two or more possible.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
C++ for Engineers and Scientists Third Edition
Visual C++ Programming: Concepts and Projects
Copyright © 2012 Pearson Education, Inc. Chapter 3 Control Structures: Selection.
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
Computer Science Selection Structures.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
1 nd Semester Module3 Selection Statement Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Selection Statement – Selection Statement Modified from Aj. Thanachat Thanomkulabut’s slide 1 st semester, 2012.
Chapter 4 Control Structures: Selection We introduced the three fundamental control structures from which all programs are developed: 1. Sequence structures.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
Control statements Mostafa Abdallah
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
Decision Statements, Short- Circuit Evaluation, Errors.
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
TestScore < 80 testScore * 2 >= < w / (h * h) x + y != 2 * (a + b) 2 * Math.PI * radius
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
1 nd Semester Module6 Review Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
Sequence, Selection, Iteration The IF Statement
LESSON 4 Decision Control Structure
Selection—Making Decisions
Expressions and Control Flow in JavaScript
.Net Programming with C#
Selection (if-then-else)
Control Structures: Selection Statement
Summary Two basic concepts: variables and assignments Basic types:
Chapter 4: Control Structures I (Selection)
CHAPTER 5: Control Flow Tools (if statement)
Control Structures: Selection Statement
Selection Control Structure
Presentation transcript:

1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department Kasetsart University, Bangkok THAILAND

1 st Semester /24 Outline  C# Overview Again  Boolean Expression  Condition Statement

1 st Semester /24 Simple C# Structure  Namespace Class  Main()Namespace Class Main() Variable & Constant Location Statements C# Structure

1 st Semester /24 C# Program with Condition Start statement1 statement2 statement3statement4 End Condition true false C# Overview

1 st Semester /24 Outline  C# Overview  Boolean Expression  Condition Statement

1 st Semester /24 Boolean Expression  Operators Math Notation C# Notation ExampleMeaning ===x == yx is equal to y? ≠ !=x != yx is not equal to y? >>x > yx is greater than y? ≥ >=x >= yx is greater than or equal to y? <<x < yx is less than y? ≤ <=x <= yx is less than or equal to y? Boolean Expression

1 st Semester /24 Compound Boolean Expression  Conditional Operators && - AND && - AND || - OR || - OR ! – NOT ! – NOT  Example (a=20; b=12) (a > 12) && (a 12) && (a < 20) (a % 2 == 0) || (b % 2 == 0) (a % 2 == 0) || (b % 2 == 0) Boolean Expression

1 st Semester /24 Precedence rules for Operators 1.( ) parentheses 2.*, /, % 3.+ – 4., = 5.==, != 6.&& 7. ││ 8.If equal precedence, left to right Boolean Expression

1 st Semester /24 Outline  C# Overview  Boolean Expression  Condition Statement

1 st Semester /24 Condition Statement  if...else  switch…case

1 st Semester /24 if statement syntax condition if (condition) statement; condition Statement; true false if statement

1 st Semester /24 Example: if statement i % 2 == 1 Ood i % 2 == 0 Even false false true true if statement

1 st Semester /24 if statement syntax with multiple statements condition if (condition){ statement1; statement2;} condition Statement1; true false Statement2; if statement

1 st Semester /24 if…else… statement syntax condition if (condition) statement1; else statement2; condition Statement2; truefalse Statement1; if statement

1 st Semester /24 Example: if…else… statement i % 2 == 1 Ood Even true false if statement

1 st Semester /24 Nested IF condtion1 statement2b true false condtion2 condtion3 statement2a statement3a true true false false if statement

1 st Semester /24 Example: Nested IF if statement

1 st Semester /24 Condition Statement  if...else  switch…case

1 st Semester /24 Switch Case Flowchart Overview x==1 x==2 x==3 x==4 x==5 cmd1; cmd2; cmd3; cmd4; cmd5; break break break break break T T T T T F F F F F

1 st Semester /24 IF statement example (x==1) if (x==1) cmd1; else if (x==2) cmd2; else if (x==3) cmd3; else if (x==4) cmd4; else if (x==5) cmd5;

1 st Semester /24 switch-case example switch (x) { case 1: cmd1; break; case 2: cmd2; break; case 3: cmd3; break; case 4: cmd4; break; case 5: cmd5; break; }

1 st Semester /24 Convert if..else… statement to switch case if (x == 5) && (x%2 == 1) { y=y+5; } else { y=y-5; }true false ((x==5) && (x%2 ==1)) case ((x==5) && (x%2 ==1)){ true: y=y+5; break; break; false: y=y-5; break; }

1 st Semester /24 Switch Case example Minor Cineplex Theater Cost (baht) Title 1180War of the world 2180War of the world 3100Batman Begins 4100Batman Begins 5140Hell!!! 6140Hell!!!

1 st Semester /24 Summary  Boolean Expression  Condition Statement if statement case statement