Sequence, Selection, Iteration The IF Statement

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: Control Structures I (Selection)
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
How SAS implements structured programming constructs
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
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)
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
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.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
1 Selection Structures. 2 Making Decisions Sample assignment statements to figure worker pay with possible overtime PayAmount = Hours * Rate PayAmount.
UNIT II Decision Making And Branching Decision Making And Looping
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
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.
Control Structures A control structure is simply a pattern for controlling the flow of a program module. The three fundamental control structures of a.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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.
Simple Control Structures IF, IF-ELSE statements in C.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Control Structures In structured programming, we use three basic control structures: –Sequence –Selection –Repetition So far, we have worked with sequential.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Control statements Mostafa Abdallah
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
1 st Semester Module3 Condition Statement อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
IST 210: PHP Logic IST 210: Organization of Data IST2101.
if ( condition ) statement; if is a Java reserved word The condition must be a boolean expression. It must evaluate to either true or false.
Relational Operator and Operations
LOGICAL CONTROL STRUCTURES (chp. 8)
AND.
Section 7.1 Logical Operators
Assignment statement:
Operator Precedence Operators Precedence Parentheses () unary
Topics The if Statement The if-else Statement Comparing Strings
Expressions and Control Flow in JavaScript
Topics The if Statement The if-else Statement Comparing Strings
2-1 Making Decisions Sample assignment statements
Computers & Programming Languages
Relational Operators Operator Meaning < Less than > Greater than
Pages:51-59 Section: Control1 : decisions
Visual Basic – Decision Statements
Summary Two basic concepts: variables and assignments Basic types:
Computer Science Core Concepts
Chapter 4: Control Structures I (Selection)
Expressions.
Chapter 5: Selection Statement
Repetition Statements (Loops) - 2
Programming Control Structures with JavaScript
Pages:51-59 Section: Control1 : decisions
Chapter 3: Selection Structures: Making Decisions
CSCI 1100/1202 February 6, 2002.
A3 2.1d To Solve Compound Inequalities
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
Presentation transcript:

Sequence, Selection, Iteration The IF Statement COBOL Sequence, Selection, Iteration The IF Statement

IF Statement Simplified basic syntax: IF condition statement What is a condition? An expression formed using relational or logical operators

Relational Operators = equal to > greater than < less than NOT = not equal to NOT > not greater than NOT < not less than >= greater than or equal to <= less than or equal to

Logical Operators AND OR Compound Conditions – conditional expressions formed by usage of one or more logical operators, for example, IF A < 100 AND B > 20 . . . IF A = 0 OR B = 0 . . . IF A > 0 AND B > 0 OR C < 0 . . .

Precedence for Evaluation of Logical Expressions HIGH simple condition (relational expression) complex condition in parentheses NOT AND LOW OR Consider: NOT (NOT A < 10 AND B = 4) {if A=6, B=6}

Precedence for Evaluation of Logical Expressions HIGH simple condition complex condition in parentheses NOT AND LOW OR Consider: NOT (NOT A < 10 AND B = 4) {if A=6, B=6} T F

Precedence for Evaluation of Logical Expressions HIGH simple condition complex condition in parentheses NOT AND LOW OR Consider: NOT (NOT A < 10 AND B = 4) {if A=6, B=6} T F ---------------- false

Precedence for Evaluation of Logical Expressions HIGH simple condition complex condition in parentheses NOT AND LOW OR Consider: NOT (NOT A < 10 AND B = 4) {if A=6, B=6} T F ---------------- false -----------------------------------

Precedence for Evaluation of Logical Expressions HIGH simple condition complex condition in parentheses NOT AND LOW OR Consider: NOT (NOT A < 10 AND B = 4) {if A=6, B=6} T F ---------------- false ----------------------------------- ------------------------------------------------- true

Logical Expressions (Conditions) Can appear in clauses other than IF statement. PERFORM …UNTIL EVALUATE other . . .

IF with ELSE Simplified basic syntax: IF condition statement(s) ELSE statement(s) END-IF