Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.

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

©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 5 Selection Statements.
Control Flow Statements: Repetition/Looping
If Statements & Relational Operators Programming.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
The If/Else Statement, Boolean Flags, and Menus Page 180
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
The switch Statement, DecimalFormat, and Introduction to Looping
UNIT II Decision Making And Branching Decision Making And Looping
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
CPS120: Introduction to Computer Science Decision Making in Programs.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
CONTROLLING PROGRAM FLOW
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
CHAPTER 8 CONTROL STRUCTURES Prepared by: Lec. Ghader R. Kurdi.
Previously Repetition Structures While, Do-While, For.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
Selection. Flow Chart If selection If/else selection Compound statement Switch.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
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.
PROGRAM FLOW CHAPTER3 PART1. Objectives By the end of this section you should be able to: Differentiate between sequence, selection, and repetition structure.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
PEG200/Saidatul Rahah 1.  Selection Criteria › if..else statement › relational operators › logical operators  The if-then-else Statement  Nested if.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 4 – Logical Operators & Branching.
CPS120: Introduction to Computer Science Decision Making in Programs.
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
Control Flow Statements
LESSON 4 Decision Control Structure. Decision Control Structures 1. if statement 2. if-else statement 3. If-else-if statement 4. nested if statement 5.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
Lesson thirteen Conditional Statement "if- else" ©
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
COMP Loop Statements Yi Hong May 21, 2015.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Loop Control อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 8.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
Branching statements.
Chapter 3 Selection Statements
Decision Making in C.
Chapter 3 Control Statements
Programming Fundamentals
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
For & do/while Loops.
Repetition Control Structure
Computer Science Core Concepts
Understanding Conditions
Program Flow.
PROGRAM FLOWCHART Selection Statements.
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.
Decisions, decisions, decisions
Branching statements Kingdom of Saudi Arabia
Presentation transcript:

Chapter 3. Control Structure C++ Programing

Conditional structure C++ programming language provides following types of decision making statements. Click the following links to check their detail. StatementDescription if statementAn if statement consists of a boolean expression followed by one or more statements. if …. else statementAn if statement consists of a boolean expression followed by one or more statements. switch statementA switch statement allows a variable to be tested for equality against a list of values. nested if statementYou can use one if or else if statement inside another if or else if statement(s). nested switch statemnetYou can use one swicth statement inside another switch statement(s).

If statement An if statement consists of a boolean expression follow by one or more statement. Syntax: if (boolean_expressoion) { //statements will execute if the boolean expression is true }

If statement (cont) Flow Diagram:

If statement (cont), example #include int main() { //local variable declaration int a=10; // check the boolean condition if(a<20) { cout<<“a is less than 20;”<<endl; } cout<<“value of a is : “ <<a<<endl; return 0; }

if…else statement An if statement can be followed by an option else statement, which executes when the boolean expression is false. Syntax: if (boolean_expressoion) { //statements will execute if the boolean expression is true } else { //statements will execute if the boolean expression is false }

if…else statement (cont)

#include int main() { //local variable declaration int a=10; // check the boolean condition if(a<20) { cout<<“a is less than 20;”<<endl; } if…else statement (cont)

else { //if condition if false then print the following cout<<“ a is not less than 20;”<<endl; } cout<<“value of a is : “ <<a<<endl; return 0; } if…else statement (cont)

if…else if…else statement An if statement can be followed by an optional else if...else statement, which is very usefull to test various conditions using single if...else if statement. When using if, else if, else statements there are few points to keep in mind. An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of he remaining else if's or else's will be tested.

if…else if…else statement(cont) Syntax: if (boolean_expression 1) { //Execute when the boolean expression 1 is true } else if (boolean_expression 2) { //Execute when the boolean expression 2 is true } else { //Execute when the none of above condition is true }

if…else if…else statement(cont)