Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:

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 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
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.
James Tam Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
J. Michael Moore Structured Programming CPSC 110 Drawn from James Tam's material.
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
2-1 Making Decisions Sample assignment statements PayAmount = Hours * Rate PayAmount = 40*Rate + (Hours – 40)*Rate*1.5.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
J. Michael Moore Structured Programming CSCE 110 Drawn from James Tam's material.
true (any other value but zero) false (zero) expression Statement 2
We will not cover the following sections in class: –7.2 –7.4 –7.8(we will discuss the design topics) You ARE responsible for knowing the topics covered.
James Tam Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Logical and Relational Expressions Nested if statements.
James Tam Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4: Control Structures: Selection
James Tam Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
1 CSC103: Introduction to Computer and Programming Lecture No 11.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
CPS120: Introduction to Computer Science Decision Making in Programs.
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.
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.
Chapter 5 Logic; Got Any?. Flow of Control The order in which the computer executes statements in a program Control Structure A statement used to alter.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 1 st semester King Saud University College of Applied studies and Community Service Csc 1101.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Conditions, Logical Expressions, and Selection Control Structures ROBERT REAVES.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CPS120: Introduction to Computer Science Decision Making in Programs.
Midterm1 answers: Page 1 1 a6 b6 c0 2 ***. Midterm1 answers: Page 2 A)a. 53b. 44c. 13d. 75e. 77 B)a. 53b. 17c. 33 / 44d. 13e. 75 C)a. ‘5’b. ‘3’c. ‘ ‘d.
Conditionals Conditional statements, called conditionals for short, are statements in the if-then or if-then-else form. Examples: “If the alarm goes off,
CPS120: Introduction to Computer Science Decision Making in Programs.
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
2 nd Semester Module3 Selection Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Sequence, Selection, Iteration The IF Statement
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Decisions Chapter 4.
Flow of Control.
Chapter 3 Branching Statements
Control Structures.
Topics The if Statement The if-else Statement Comparing Strings
Chapter 4: Control Structures I (Selection)
2-1 Making Decisions Sample assignment statements
The C++ IF Statement Part 2 Copyright © Curt Hill
CSC215 Lecture Flow Control.
Chapter#3 Structured Program Development in C++
CSC215 Lecture Control Flow.
Chapter 8: More on the Repetition Structure
Chapter 4: Control Structures I (Selection)
Chapter 5 Decisions.
PROGRAM FLOWCHART Selection Statements.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
CSC215 Lecture Control Flow.
Presentation transcript:

Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include: –if statements –case statements

Pascal Programming Today Chapter 4 2 If-then-else Statements Syntax of if-then-else statements if then else May be a Boolean constant, Boolean variable or Boolean expression.

Pascal Programming Today Chapter 4 3 If-then-else Statements Syntax of if-then-else statements if then else Will be executed if is TRUE.

Pascal Programming Today Chapter 4 4 If-then-else Statements Syntax of if-then-else statements if then else Will be executed if is FALSE.

Pascal Programming Today Chapter 4 5 Flowchart of an if-then-else statement

Pascal Programming Today Chapter 4 6 »Sometimes, more than one statement is required to be executed under the condition. »In such case, a compound statement should be used.

Pascal Programming Today Chapter 4 7 »A compound statement consists of two or more simple statements enclosed by a pair of reserved words begin and end.

Pascal Programming Today Chapter 4 8 Syntax of if-then-else statements with compound statements if then begin ;  end else begin ;  end Compound statement

Pascal Programming Today Chapter 4 9 Flowchart of an if- then-else statement with compound statements

Pascal Programming Today Chapter 4 10 If-then Statements Syntax of if-then statements if then

Pascal Programming Today Chapter 4 11 Flowchart of an if-then statement

Pascal Programming Today Chapter 4 12 Syntax of if-then statements with compound statements if then begin ;  end

Pascal Programming Today Chapter 4 13 Flowchart of an if-then statement with compound statement

Pascal Programming Today Chapter 4 14 Nested If Statements »An if statement may be nested by another if statement to form a nested if statement.

Pascal Programming Today Chapter 4 15 Syntax of nested if statements if then if then else else if then else

Pascal Programming Today Chapter 4 16 Flowchart of a nested if statement

Pascal Programming Today Chapter 4 17 »Reserved word else should be matched to the nearest preceding if in nested if statements.

Pascal Programming Today Chapter 4 18 Case Statements »A case statement is preferred for selection involving more than three alternatives.

Pascal Programming Today Chapter 4 19 Syntax of case statements case of : ;  : end A variable or an expression of ordinal data types ( integer, char or Boolean ).

Pascal Programming Today Chapter 4 20 Syntax of case statements case of : ;  : end Lists of possible values of.

Pascal Programming Today Chapter 4 21 Syntax of case statements case of : ;  : end Simple or compound statements.

Pascal Programming Today Chapter 4 22 »Only one selection on the list of statements will be executed. »No statements will be executed if no case label match the selector.