Control Flow Statements

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

1 Conditional Statement. 2 Conditional Statements Allow different sets of instructions to be executed depending on truth or falsity of a logical condition.
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.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
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.
true (any other value but zero) false (zero) expression Statement 2
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control if-else and switch statements.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
UNIT II Decision Making And Branching Decision Making And Looping
Basics of “C” Programming
Chapter 4 Program Control Statements
Conditional Statements While writing a program, there may be a situation when you need to adopt one path out of the given two paths. So you need to make.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
1 CSC103: Introduction to Computer and Programming Lecture No 11.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
C# Programming Fundamentals Control Flow Jim Warren, COMPSCI 280 S Enterprise Software Development.
sequence of execution of high-level statements
Controlling Execution Dong Shao, Nanjing Unviersity.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
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.
1 2. Program Construction in Java. 2.4 Selection (decisions)
Lecture #7 CONTROL STRUCTURE & FLOW CHARTS
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Control Statements in C 1.Decision making statements 2.Looping statements 3.Branching statements
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 4 Control Structures I: Selection.
Chapter 4 Control Structures I. Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form and evaluate.
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
CS 161 Introduction to Programming and Problem Solving Chapter 18 Control Flow Through C++ Program Herbert G. Mayer, PSU Status 10/8/2014 Initial content.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Asstt. Prof Mandeep Kaur Computer Dept. TOPIC: Control Statements in C language.
CSI 3125, Preliminaries, page 1 Control 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.
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 5 – Decision Making. Structured Programming Sequence Selection Repetition yesno yes no.
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.
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.
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 #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
 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.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
‘C’ Programming Khalid Jamal.
Decisions Chapter 4.
Statements (6 of 6) A statement causes an action to be performed by the program. It translates directly into one or more executable computer instructions.
Condition Statements.
Control Structures.
Flow of Control.
11/10/2018.
IF if (condition) { Process… }
Control Structures: Selection Statement
Conditionals.
Program Flow.
ECE 103 Engineering Programming Chapter 20 Change in Flow of Control
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.
Control Structures: Selection Statement
break & continue Statements
Presentation transcript:

Control Flow Statements

Control FLOW Statements C language has decision making capabilities and supports controlling of statements. C supports following decision making statements: 1. IF 2.IF-ELSE and its various form 3. Switch 4. Conditional Operator

If statement The if statement is a powerful decision making statement. The if statement is used to control the flow of execution of statements. It is a two way decision statement which is used in conjunction with an expression.

Different forms of If statement Simple If statement. If…..else statement. Nested if…..else statement. Else if ladder.

Simple if statement If the if expression evaluates to true, the block following the if statement or statements are executed. The general form of a simple if statement is : if (test-expression) { statement-block; } statement-x;

If….Else statement The general form of if……else statements is : IF the if expression evaluates to true, the block following the if statement or statements are executed. The else statement is optional. It is used only if a statement or a sequence of statements are to be executed in case the if expression evaluates to false.

Else if ladder The general form of else if ladder is: The if – else – if statement is also known as the if-else-if ladder or the if-else-if staircase. The conditions are evaluated from the top downwards.

Nested if…else statement The general form of nested if…else statement is: if (test-expression 1) { if (test-expression 2) statement 1; } else statement 2; statement 3; Statement x;

Switch – case statement The switch-case control statement is a multi-way decision maker that tests the value of an expression against a list of integers or character constants. When a match is found, the statements associated with that constant are executed. The syntax of switch-case is:-

Jumping Statement Break Continue Goto

Break statement When the keyword break is encountered inside any c loop, control automatically passes to the first statement after the loop. A break is usually associated with an if. The general syntax of break statement is: For(; ;) { -------- if (error) break; ------- }

Continue statement In some programming situations we want to take the control to the beginning of the loop, by passing the statements inside the loop which have not yet been executed. The Keyword continue allows us to do this. When the keyword continue is encountered inside any C loop, control automatically passes to the beginning of the loop. A continue is usually associated with an if.

#include<stdio.h> void main() { int i,j; for(i=1;i<=2;i++) for(j=1;j<=2;j++) if(i==j) continue; printf(“%d%d”,i,j); } } }

Output 1 2 2 1

Go to statement C supports the go to statement to branch unconditionally from one point to another in the program. It requires a label in order to identify the place where branch is to be made. The general syntax of go to statement is: go to label; -------- label: statement x ;

Thanks…..