Conditionals.

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.
Control Structures.
The if-else Statements
Fundamental of C programming
Decision Making EE2372 Software Design I Dr. Gerardo Rosiles.
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Control Structures Corresponds with Chapters 3 and 4.
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 4 Control Structures I: Selection.
The switch Statement, DecimalFormat, and Introduction to Looping
Switch Statements Comparing Exact Values. 2 The Switch Statement The switch statement provides another way to decide which statement to execute next The.
JAVA Control Statement.
UNIT II Decision Making And Branching Decision Making And Looping
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Chapter 4 Program Control Statements
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second.
Chapter 4: Control Structures I J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
Chapter 4: Control Structures I
DiagrammaticRepresentation Iteration Construct False True Condition Exit from Statement (s) loop Sequence construct Selection construct Statement 1 Statement.
Chapter 3:Decision Structures.  3.1 The if Statement  3.2 The if-else Statement  3.3 The if-else-if Statement  3.4 Nested if Statements  3.5 Logical.
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,
A First Book of ANSI C Fourth Edition Chapter 4 Selection.
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.
Control Structures 1. Control Structures Java Programming: From Problem Analysis to Program Design, D.S. Malik 2.
Chapter 4: Control Structures SELECTION STATEMENTS.
Switch Statements Comparing Exact Values. The Switch Statement: Syntax The switch statement provides another way to decide which statement to execute.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Sahar Mosleh California State University San MarcosPage 1 Program Control Statement.
J AVA P ROGRAMMING 2 C H 03: C ONTROL STATEMENTS if, for loop (review) switch, while, do while break, continue Fall Java Programming.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
Decision Statements, Short- Circuit Evaluation, Errors.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Information and Computer Sciences University of Hawaii, Manoa
If/Else Statements.
Chapter 4: Control Structures I
CNG 140 C Programming (Lecture set 3)
‘C’ Programming Khalid Jamal.
Course Outcomes of Programming In C (PIC) (17212, C203):
Decision Making in C.
Chapter 4: Control Structures I
The switch Statement, and Introduction to Looping
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
Lecture 3- Decision Structures
Programming Fundamentals
Control Structures.
Chapter 4: Control Structures I
IF if (condition) { Process… }
Selection CSCE 121 J. Michael Moore.
The switch statement: an alternative to writing a lot of conditionals
CSE 1020:Control Structure
Visual Basic – Decision Statements
Chapter 4: Control Structures I (Selection)
Control Structure Chapter 3.
Lecture Notes – Week 2 Lecture-2
The Java switch Statement
Program Flow.
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.
Control Structure.
ICS103: Programming in C 4: Selection Structures
Presentation transcript:

Conditionals

Conditions – Decision making Decision Making in programming is similar to decision making in real life. In programming also we face some situations where we want a certain block of code to be executed when some condition is fulfilled. A programming language uses control statements to control the flow of execution of program based on certain conditions. These  are used to cause the flow of execution to advance and branch based on changes to the state of a program.

If Syntax: if(condition) { // Statements to execute if // condition is true }

If-Else Syntax: if (condition) { // Executes this block if // condition is true } else // condition is false

Nested If Syntax: if (condition1) { // Executes when condition1 is true if (condition2) // Executes when condition2 is true }

if-else-if ladder Syntax: if (condition) statement; else if (condition) . else if-else-if ladder: Here, a user can decide among multiple options.The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. If none of the conditions is true, then the final else statement will be executed.

switch-case switch (expression) { case value1: statement1; break; . case valueN: statementN; default: statementDefault; } The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression. Expression can be of type byte, short, int char or an enumeration. Beginning with JDK7, expressioncan also be of type String. Dulplicate case values are not allowed. The default statement is optional. The break statement is used inside the switch to terminate a statement sequence. The break statement is optional. If omitted, execution will continue on into the next case.

Break statement

Continue Statement