Introduction Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Objectives What are control structures Relational.

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

TRUTH TABLES The general truth tables for each of the connectives tell you the value of any possible statement for each of the connectives. Negation.
Chapter 3 section 2. Please form your groups The 1 st column represents all possibilities for the statement that can be either True or False. The 2 nd.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
Control Structures Control structures are used to manage the order in which statements in computer programs will be executed Three different approaches.
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Repetition Chapter 4: Control structures. Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Loop Statements After reading and studying this Section,
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
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.
Chapter 2: Java Fundamentals Operators. Introduction to OOP Dr. S. GANNOUNI & Dr. A. TOUIR Page 2 Content Group of Operators Arithmetic Operators Assignment.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Conditional Statements Control Structures.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Visual C++ Programming: Concepts and Projects
Variables, Constants and Built-in Data Types Chapter 2: Java Fundamentals.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
BUILDING COMPUTER CIRCUITS prepared by Burak Galip ASLAN September, 2006 BOOLEAN LOGIC AND GATES CONTROL CIRCUITS.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
BY: MISS FARAH ADIBAH ADNAN IMK. CHAPTER OUTLINE: PART III 1.3 ELEMENTARY LOGIC INTRODUCTION PROPOSITION COMPOUND STATEMENTS LOGICAL.
Conditional Control Flow By Muhammad Ahsan Qadar SACS Programming Fundamentals Workshop 1.
CPS120: Introduction to Computer Science Decision Making in Programs.
An Introduction to Programming Using Alice Boolean Logic.
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.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
CPS120: Introduction to Computer Science Decision Making in Programs.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
WHILE STATEMENTS. This is the common structure of While statements initialize variables //initialize while (condition) { // test perform calculations.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Algorithm Design.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
CHAPTER 1.3 THE OPERATORS Dr. Shady Yehia Elmashad.
Algorithms Writing instructions in the order they should execute.
Warmup Answer the following True/False questions in your head: I have brown hair AND I am wearing glasses I am male OR I am wearing sneakers I am NOT male.
Chapter 51 Decisions Relational and Logical Operators If Blocks Select Case Blocks.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 CS 177 Week 5 Recitation Booleans and Control Flow.
CPS120: Introduction to Computer Science Decision Making in Programs.
Visual Basic CDA College Limassol Campus COM123 Visual Basic Programming Semester C Lecture:Pelekanou Olga Week 4: Understand and implement Decisions.
Fundamental Logic Gates And, Or, Not. Logic Gates: The Basics Regulate the flow of electricity within circuits to perform desired functionalities Each.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 2: Fundamental Programming Structures in Java Adapted from MIT AITI Slides Control Structures.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
CS 106 Logic and Conditionals (Boolean Expressions)
CHAPTER 2 PART #4 OPERATOR 1 st semester King Saud University College of Applied studies and Community Service Csc
Fundamentals 2 1. Programs and Data Most programs require the temporary storage of data. The data to be processed is stored in a temporary storage in.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Relational Operator and Operations
Sequence, Selection, Iteration The IF Statement
Computers & Programming Languages
Computers & Programming Languages
Chapter 8: More on the Repetition Structure
Introduction to Programming Using Python PART 2
Selection Statements.
Computer Science Core Concepts
Chapter 2: Java Fundamentals
Understanding Conditions
Relational Operators.
If-Statements and If/Else Statements
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:

Introduction Chapter 4: Control structures

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 2 Objectives What are control structures Relational Operators Logical operators Boolean expressions Conditional (Decision) statements Loop statements

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 3 What are Control Structures Without control structures, a computer would evaluate the instructions in a program step-by-step Control structures allow: Defining which instructions are evaluated Changing the order in which instructions are evaluated and Controlling the “flow” of the program Control structures include: Block statements (anything contained within curly brackets) Decision statements Loops

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 4 Relational Operators Relational operators produce boolean values. ==Equal to !=Not equal to <Less than <=Less than or equal to >Greater than >=Greater than or equal to

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 5 Use of relational Operators left_operand relational_operator right_operand counter < 5 counter <= maximum Relational operators can be combined with arithmetic operators: < 4  false because 8 is not < 4 myNumber % 2 == 1  false if myNumber is odd  true otherwise Relational operators are always performed last!!

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 6 Logical Operators Symbol Operator Name && AND || OR ! NOT || TF TTT FTF && TF TTF FFF TF ! FT

Introduction to OOPDr. S. GANNOUNI & Dr. A. TOUIRPage 7 Boolean Expressions Boolean expression is an expression that is evaluated to a boolean value. Atomic Boolean expression uses one and only one of the relational operators. myBalance <= yourBalance Complex Boolean expressions may be defined by linking other Boolean expressions using logical operators. (myBalance 20) (! (myBalance <= yourBalance) ) !! (yourAge <= 20) Boolean expressions may be assigned to boolean variables. boolean isHeOlder = (myAge < hisAge) ;