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.

Slides:



Advertisements
Similar presentations
Selection Feature of C: Decision making statements: It allow us to take decisions as to which code is to be executed next. Since these statements control.
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.
If Statements, Try Catch and Validation. The main statement used in C# for making decisions depending on different conditions is called the If statement.
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.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Decision Making EE2372 Software Design I Dr. Gerardo Rosiles.
This section gives several examples of if statements. In this first example, if a certain condition holds true, the single line of code immediately following.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Conditional Statements If these were easy then everyone would them!
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
If Statements & Relational Operators, Part 2 Programming.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
Simple Control Structures IF, IF-ELSE statements in C.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 21, 2005 Lecture Number: 10.
1 Week 6 Branching. 2 What is “Flow of Control”? l Flow of Control is the execution order of instructions in a program l All programs can be written with.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
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.
Conditional Structures UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
CSE 1341 Honors Note Set 05 Professor Mark Fontenot Southern Methodist University.
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.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Lesson thirteen Conditional Statement "if- else" ©
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C++ 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
Lecture #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
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.
Branching statements.
If/Else Statements.
Decision Making in C.
Selection (also known as Branching) Jumail Bin Taliba by
Control Structures.
Lecture 3- Decision Structures
Programming Fundamentals
Control Structures.
Loop Control Structure.
JavaScript Selection Statement Creating Array
IF if (condition) { Process… }
Control Structures: Selection Statement
Visual Basic – Decision Statements
Lab5 PROGRAMMING 1 Loop chapter4.
Conditionals.
Program Flow.
Control Structures: Selection Statement
Decision making and control functions
Branching statements Kingdom of Saudi Arabia
Presentation transcript:

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 arises in programming

Decision making statements available in C are : if statement if statement if..else statements if..else statements nested if statements nested if statements

if statement i.e if a certain condition is true then a block of statement is executed otherwise not. Syntax: if(condition) { // Statements to execute if // condition is true }

if statement If we do not provide the curly braces ‘{‘ and ‘}’ after if( condition ) then by default if statement will consider the first immediately below statement to be inside its block. example if(condition) statement1; statement2; // Here if the condition is true, if block // will consider only statement1 to be inside // its block.

..

example int main( ) { int i = 10; if (i > 15) { cout<<"10 is less than 15"; } cout<<"I am Not in if"; } Output: I am Not in i

if -else if we want to do something else if the condition is false. Here comes the else statement. We can use the else statement with if statement to execute a block of code when the condition is false. if (condition) { // Executes this block if // condition is true } else { // Executes this block if // condition is false }

.

example int main() { int i = 20; if (i < 15) cout<<"i is smaller than 15"; else cout<<"i is greater than 15"; return 0; } Output: i is greater than 15 Output: i is greater than 15

if statements within if statements. i.e, we can place an if statement inside another if statement. if (condition1) { // Executes when condition1 is true if (condition2) { // Executes when condition2 is true }

..

. int main() { int i = 10; if (i == 10) { // First if statement if (i < 15) cout<<"i is smaller than 15"; // Nested - if statement // Will only be executed if statement above // it is true }

cont.... if (i < 12) cout<<"i is smaller than 12 too"; else cout<<"i is greater than 15"; } return 0; Output: i is smaller than 15 i is smaller than 12 too

its enough thanks you