Lesson thirteen Conditional Statement "if- else" © www.waxkabaro.com.

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.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Lesson 5 - Decision Structure By: Dan Lunney
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
CS-1010 Dr. Mark L. Hornick 1 Selection Statements and conditional expressions.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
1 Fall 2007ACS-1903 Chapter 3 Decision Structures The if Statement The if-else Statement The if-else-if Statement Nested if Statements Logical Operators.
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
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 Fall 2008ACS-1903 Chapter 3 Decision Structures The if Statement The if-else Statement The if-else-if Statement Nested if Statements Logical Operators.
(c) 2003 E.S.Boese1 Conditionals Chapter 10 - Student.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Use Precedence Chart int number ; float x ; number ! = 0 && x < 1 / number / has highest priority < next priority != next priority && next priority What.
Lecture 11. Today’s topic Conditional statement –Relational operators –if statement –if-else statement –If-elseif statement.
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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Conditional statements Dept. of Computer Engineering Faculty of Engineering, Kasetsart University Bangkok, Thailand.
Conditionals & boolean operators
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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.
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,
Simple Control Structures IF, IF-ELSE statements in C.
CONTROLLING PROGRAM FLOW
Chapter 6: Control Structures Computer Programming Skills Second Term Department of Computer Science Foundation Year Program Umm Alqura.
Building Java Programs
Decision Making Selection structures (if....else and switch/case)
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
The if-else statement. The if-else statement in Java The if-else statement is the second conditional statement in Java The if-else statement selects one.
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.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Conditionals-part21 Conditionals – part 2 Barb Ericson Georgia Institute of Technology Nov 2009.
CONDITIONALS. Boolean values Boolean value is either true or false It is name after the British mathemetician, George Boole who first formulated Boolean.
ITK 168 Decisions Dr. Doug Twitchell September 20, 2005.
Control statements Mostafa Abdallah
Student Q and As from 5.1 – 5.7, 5.11 Students of CS104, Fall 2013 (and me)
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter three Conditional Statements ©
While ( number
Conditional statements and boolean expressions Arithmetic, relational and logical operators.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
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.
Computer Science 1000 LOGO II. Boolean Expressions like Excel and Scratch, LOGO supports three Boolean operators less than (
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
JavaScript: Control Statements I
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
زبان بدن Body Language.
IF if (condition) { Process… }
Pages:51-59 Section: Control1 : decisions
SELECTIONS STATEMENTS
Logic of an if statement
Understanding Conditions
CS2011 Introduction to Programming I Selections (I)
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.
Pages:51-59 Section: Control1 : decisions
If-Statements and If/Else Statements
Presentation transcript:

Lesson thirteen Conditional Statement "if- else" ©

Definition In C#, as in most of the programming languages there is a conditional statement with else clause: the if-else statement. Its format is the following: if (Boolean expression) { Body of the conditional statement; } else { Body of the else statement; } ©

How It works This statement works as follows: the expression in the brackets (a Boolean expression) is calculated. The calculation result must be Boolean – true or false. Depending on the result there are two possible outcomes. If the Boolean expression is calculated to true, the body of the conditional statement is executed and the else-statement is omitted and its operators do not execute. Otherwise, if the Boolean expression is calculated to false, the else-body is executed, the main body of the conditional statement is omitted and the operators in it are not executed. ©

Illustration ©

Conditional Statement "if- else" – Example int x = 2; if (x > 3) { Console.WriteLine("x is greater than 3"); } else { Console.WriteLine("x is not greater than 3"); } ©

Nested "if" Statements Next Lesson ©