Estructura de Selección

Slides:



Advertisements
Similar presentations
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Advertisements

CSC 142 G 1 CSC 142 Conditionals [Reading: chapter 5]
Introduction to Programming Lecture 5. In the Previous Lecture Basic structure of C program Basic structure of C program Variables and Data types Variables.
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
If Statements & Relational Operators Programming.
An Introduction to Programming with C++ Fifth Edition Chapter 5 The Selection Structure.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Week 4 Selections This week shows how to use selection statements for more flexible programs. It also describes the various integral types that are available.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Branch Statements (Decision). Flow of Control  The order in which a program performs actions.  A branching statement chooses one of two or more possible.
C++ for Engineers and Scientists Third Edition
CSCI 130 Chapter 4 Statements, Expressions, and Operators.
CSci 125 Lecture 10 Martin van Bommel. Simple Statements Expression followed by semicolon Assignments total = n1 + n2; Function calls printf(”Hello.\n”);

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.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Logical Operators Jumps Logical Operators The different logical operators found in Java Rational Operators The different rational operators found in Java.
Chapter 4: Making Decisions. Resource: Starting Out with C++, Third Edition, Tony Gaddis 4.1 Relational Operators Relational operators allow you to compare.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Agenda Basic Logic Purpose if statement if / else statement
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
CSCI 161 Lecture 7 Martin van Bommel. Control Statements Statements that affect the sequence of execution of other statements Normal is sequential May.
In the last lesson we discussed about: Casting Precedence The “=“ used as an assignment operator Made a calculate average program.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
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,
Lecture 01b: C++ review Topics: if's and switch's while and for loops.
Control Statements: Part1  if, if…else, switch 1.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Lesson 4: Introduction to Control Statements 4.1 Additional Operators Extended Assignment Operators –The assignment operator can be combined with the.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
 Type Called bool  Bool has only two possible values: True and False.
Lesson #4 Logical Operators and Selection Statements.
Lesson #4 Logical Operators and Selection Statements.
Chapter 4: Control Structures I
Sequence, Selection, Iteration The IF Statement
Operator Precedence Operators Precedence Parentheses () unary
Chapter 4: Control Structures
C# and the .NET Framework
Javascript Conditionals.
An Introduction to Programming with C++ Fifth Edition
If statement.
Branching Chapter 5 11/14/16 & 11/15/
AP Java Review If else.
Programming 2 Decision-Making.
Selection Control Structure
Summary Two basic concepts: variables and assignments Basic types:
JavaScript Part 2.
Computer Science Core Concepts
Chapter 4: Control Structures I (Selection)
Logic of an if statement
Programming Concepts and Database
Beginning C Lecture 3 Lecturer: Dr. Zhao Qinpei
AP Java Review If else.
Relational Operators.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Decision making and control functions
Chapter 5: The Selection Structure
If-Statements and If/Else Statements
Web Development & Design Foundations with HTML5 7th Edition
Presentation transcript:

Estructura de Selección COMP 232 Prof. Carlos Rodríguez Sánchez

Flujogramas If selection structure start Price = price * 1.1 F stop Enter Part number & price T Price = price * 1.1 Part number = “AB203” F Display “Price increase” Display part number & price stop

Flujogramas start If/else selection structure A Enter sales T Display commission T Commission = .02 * sales Sales > 1500 stop F Commission = .01 * sales A

Codificando la Estructura de Selección Formato: if (condición) one statement or a block of statements enclosed in braces, to be processed when the condition is true [else one statement or a block of statements enclosed in braces, to be processed when the condition is false]

if (condition) one statement { multiple statements require braces } else multiple statements require braces

Operadores de comparación utilizados en C++ Operator Operation Precedence number < <= > >= == != less than less than or equal to greater than greater than or equal to equal to not equal to 1 2

Ejemplos if statement’s condition Meaning if (quantity < 50) if (age >= 25) if (onhand == targed) if (quantity != 7500)

Using Comparison Operators in a Program start a Enter first number & second number Display first number & second number Assign first number to temp T first number > second number Assign second number to first number stop F Assign temp to second number a