Chapter three Conditional Statements © www.waxkabaro.com.

Slides:



Advertisements
Similar presentations
1 Chapter Five Selection and Repetition. 2 Objectives How to make decisions using the if statement How to make decisions using the if-else statement How.
Advertisements

Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
July 13 th.  If/ Else if / Else  Variable Scope  Nested if/else's  Switch statements  Conditional Operator.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
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.
Visual C++ Programming: Concepts and Projects
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Parameters, Arguments, Local Variables, and Scope CSC 1401: Introduction to Programming with Java Week 8 – Lecture 1 Wanda M. Kunkle.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
Implementing Control Logic in C# Svetlin Nakov Telerik Corporation
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Python quick start guide
Functions in C. Consider #include main() { int i; for(i=1; i
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
BIM313 – Advanced Programming Techniques Flow Control 1.
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
Conditional Statements Implementing Control-Flow Logic in C# SoftUni Team Technical Trainers Software University
Loops Repeating Code Multiple Times SoftUni Team Technical Trainers Software University
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Agenda Exam #1 Review Modulus Conditionals Boolean Algebra Reading: Chapter Homework #5.
CIS 234: LOOPS Adapted from materials by Dr. Donald Bell, 2000 (updated April 2007)
Simple Control Structures IF, IF-ELSE statements in C.
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
CPS120: Introduction to Computer Science Decision Making in 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.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
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.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Copyright 2003 Scott/Jones Publishing Making Decisions.
Compound Statements If you want to do more than one statement if an if- else case, you can form a block of statements, or compound statement, by enclosing.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
1 Chapter 4: Basic Control Flow ► Chapter Goals  To be able to implement decisions using if statements  To understand statement blocks  To learn how.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
Introduction to C Programming CE Lecture 3 Control Structures in C.
Chapter 3 1 l Branching l Loops l exit(n) method l Boolean data type and logic expressions Flow of Control – Part 1.
CPS120: Introduction to Computer Science Decision Making in Programs.
Decision Statements, Short- Circuit Evaluation, Errors.
Lesson thirteen Conditional Statement "if- else" ©
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 2 Review of 1301 and C# Richard Gesick. Common data types int, long, double, float, char, bool, string.
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Engineering Computing I Chapter 3 Control Flow. Chapter 3 - Control Flow The control-flow of a language specify the order in which computations are performed.
Chapter 3. Control Structure C++ Programing. Conditional structure C++ programming language provides following types of decision making statements. Click.
Python Arithmetic Operators OperatorOperationDescription +AdditionAdd values on either side of the operator -SubtractionSubtract right hand operand from.
Silberschatz and Galvin  C Programming Language Decision making in C Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
IF STATEMENTS AND BOOLEAN EXPRESSIONS. BOOLEAN EXPRESSIONS Evaluate to a value of true or false Use relational or equivalence operators Boolean operators.
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Repeating Code Multiple Times
Basics programming concepts-2
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
Chapter 4: Making Decisions.
Midterm Exam Preperation
IF if (condition) { Process… }
Lecture 1 Review of 1301/1321 CSE /26/2018.
Controlling Program Flow
Presentation transcript:

Chapter three Conditional Statements ©

Lesson Twelve If statement ©

Definition Conditional statements if and if-else are conditional control statements. Because of them the program can behave differently based on a defined condition checked during the execution of the statement. ©

Format Conditional Statement "if" The main format of the conditional statements if is as follows: if (Boolean expression) { Body of the conditional statement; } ©

Explanation The Boolean expression can be a Boolean variable or Boolean logical expression. Boolean expressions cannot be integer (unlike other programming languages like C and C++). The body of the statement is the part locked between the curly brackets: {}. It may consist of one or more operations (statements). When there are several operations, we have a complex block operator, i.e. series of commands that follow one after the other, enclosed in curly brackets. ©

Conditional Statement "if" - Example { Console.WriteLine("Enter two numbers."); Console.Write("Enter first number: "); int firstNumber = int.Parse(Console.ReadLine()); Console.Write("Enter second number: "); int secondNumber = int.Parse(Console.ReadLine()); int biggerNumber = firstNumber; if (secondNumber > firstNumber) { biggerNumber = secondNumber; } Console.WriteLine("The bigger number is: {0}", biggerNumber); Console.ReadLine(); } ©

Conditional Statement "if" and Curly Brackets If we have only one operator in the body of the if- statement, the curly brackets denoting the body of the conditional operator may be omitted, However, it is a good practice to use them even if we have only one operator. This will make the code is more readable. ©

Conditional Statement "if- else " Next Lesson ©