The "if structure" is used to execute statement(s) only if the given condition is satisfied.

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

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.
Open Sentences.
Control Flow Statements: Repetition/Looping
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
The If Then Else Statement Using JavaScript TIP The If Statement is the fundamental control structure that allows branches in the flow of control in a.
Lecture Notes 3 Loops (Repetition)
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
Announcements Quiz 1 Posted on blackboard Handed Back (and Gone Over)Next Monday “Only a Quiz” Counts 5% of Final Grade Exam 1 Counts 10%
True/False. False True Subject May Go Here True / False ? Type correct answer here. Type incorrect answer here.
CS 1400 Chapter 5, section 2. Loops! while (rel-expression)while (rel-expression) {statements statement } if the relational-expression is true, execute.
1 Lecture 14 Chapter 6 Looping Dale/Weems/Headington.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
Step 1: Simplify Both Sides, if possible Distribute Combine like terms Step 2: Move the variable to one side Add or Subtract Like Term Step 3: Solve for.
Find opposites of numbers EXAMPLE 4 a. If a = – 2.5, then – a = – ( – 2.5 ) = 2.5. b. If a =, then – a = –
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.
Syntax : If ( Expression ) If ( Expression ) {Statements; } Example : ?>
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
TABLES AND VALUES Section 1.5. Open Sentence Equation.
Solving Systems Using Elimination
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
“If John studies then he will get an A.” s a s a F F T F T T T T T T F F.
Graphing a Two Variable Inequality. Examining the Solutions of a Linear Equation Are the following points solutions to the equation y = -2x + 3 ? Justify.
Lesson thirteen Conditional Statement "if- else" ©
Sum of Arithmetic Sequences. Definitions Sequence Series.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
5-5 Indirect Proof. Indirect Reasoning: all possibilities are considered and then all but one are proved false. The remaining possibility must be true.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Infinite for Loop If you omit the test condition, the value is assumed to be TRUE so the loop will continue indefinitely unless you provide some other.
8.1 Determine whether the following statements are correct or not
C++ Iterative Constructs
while Repetition Structure
Graphing a System of Inequalities
3 – Graphs of Inequalities (No Calculator)
A computer program is a sequence of computer commands.
For Loops October 12, 2017.
Iteration with While You can say that again.
البرمجة بلغة الفيجول بيسك ستوديو
Who Wants To Be A Millionaire?
IF Statements.
Conditional Statements
Find the reference angle for the angle measuring {image}
- Finish Unit 1 test - Solving Equations variables on both sides
SECTION 2-4 : SOLVING EQUATIONS WITH THE VARIABLE ON BOTH SIDES
Is the statement below true or false
Sullivan Algebra and Trigonometry: Section 13.4
Understanding Conditions
Relational Operators.
CS150 Introduction to Computer Science 1
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.
CS149D Elements of Computer Science
PROGRAM FLOWCHART Iteration Statements.
LI4 Inequalities- True or False?.
Systems of Linear Equations: An Introduction
© T Madas.
Chapter 2 Sets Active Learning Lecture Slides
Inequalities TRUE FALSE.
If there is any case in which true premises lead to a false conclusion, the argument is invalid. Therefore this argument is INVALID.
True or False True or False
If there is any case in which true premises lead to a false conclusion, the argument is invalid. Therefore this argument is INVALID.
Presentation transcript:

The "if structure" is used to execute statement(s) only if the given condition is satisfied.

IF TRUE False { Statement } { Statement }

if (average>60) { cout<<"passed"; // if the average is greater than 60print passed. } if (average<=60) { cout<<"failed"; // if the average is less than or equal to 60 print failed. }

We can additionally specify what we want to do if the condition does not hold with else. While the if statement lets a program decide whether a statement or block is executed, the if/else statement lets a program decide which of two statements or blocks is executed. This can be illustrated as :

if (average>60) cout<<"passed"; //if the average is greater than 60 prints passed. else cout<<"failed"; //if condition does not hold thenprints failed.

Homework Write a program that decides if a number is odd or even. Input : An integer. Output : "Odd" or "Even". Hint : Even numbers are divisible by 2. That is to say when an even number is divided by 2, the remainder is 0. Use modulus operator (%) to obtain the remainder.