FLOW OF CONTROL.

Slides:



Advertisements
Similar presentations
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
Advertisements

1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
Chapter 5: Control Structures II (Repetition)
Chapter 8 . Sequence Control
Statement-Level Control Structures Sections 1-4
CSM-Java Programming-I Spring,2005 Control Flow Lesson - 3.
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) 
1 4.8The do/while Repetition Structure The do/while repetition structure –Similar to the while structure –Condition for repetition tested after the body.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
DiagrammaticRepresentation Iteration Construct False True Condition Exit from Statement (s) loop Sequence construct Selection construct Statement 1 Statement.
CPS120 Introduction to Computer Science Iteration (Looping)
Slide 1 PHP Operators and Control Structures ITWA 133.
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Switch Statement Is a selection control structure for multi-way branching. SYNTAX switch ( IntegralExpression ) { case Constant1 : Statement(s); // optional.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
OBJECTIVES  Illustration of the Concept of Control Flow  Types of Control Flow  Knowledge about conditional and repetitive statements.  Make more.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
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,
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
Chapter 05 (Part III) Control Statements: Part II.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
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
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.
CPS120 Introduction to Computer Science Iteration (Looping)
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
1 Programming in C++ Dale/Weems/Headington Chapter 9 Additional Control Structures (Switch, Do..While, For statements)
We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.
Control Flow Statements
CSI 3125, Preliminaries, page 1 Control Statements.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
CONTENTS Loop Statements Parts of a loop Types of Loops Nested Loops
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.
 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.
Fundamentals of PL/SQL part 2 (Basics)
Chapter 6: Loops.
REPETITION CONTROL STRUCTURE
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
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.
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
C Program Controls + Flow Structure
Quick Test What do you mean by pre-test and post-test loops in C?
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 6: Conditional Statements and Loops
JavaScript: Control Statements.
Control Structures.
Chapter 6 Decision Making and Looping
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
Repetition Control Structure
Control Structures Part 3
Control Structures Part 1
Conditionals.
Program Flow.
Department of Computer Science
CSC215 Lecture Control Flow.
Presentation transcript:

FLOW OF CONTROL

FLOW OF CONTROL Contents 1. Statements 2. Selection statements i) if statements ii) switch statement 3. Iteration statements i) for loop ii) while loop iii) do-while 4. Jumb statement i) goto ii) break iii) continue

STATEMENTS The instructions given to the computer to perform the action. { statement1 ; statement2 ; . } Statements are terminated with a semicolon. The simplest statement is the Empty or null statement.

SELECTION STATEMENT if statement nested ifs if-else-if ladder switch statement

if STATEMENT If the condition evaluates to true, a course-of-action is followed otherwise the course of action is ignored Syntax if(expresssion) { statement; }

Nested ifs STATEMENT Syntax if(expresssion1) { -- -- if(expression2) [else statement2;] } else body of else;

if-else-if STATEMENT Syntax if(expresssion1) { statement 1; } else if(expression2) statement2; statement 3;

switch STATEMENT Syntax switch(expresssion) { case constant 1 : statement sequence 1; break; case constant 2 : statement sequence 2; case constant 3 : statement sequence 3; : case constant -1 : statement sequence n-1; [default : statement sequence n ] }

ITERATION STATEMENT Allow a set of instructions to be performed repeatedly until a certain condition is fulfilled for loop while loop do-while loop

for Loop Syntax Execute for(intializationexpression(s); test-expression; update expressions) { body- of – the – loop; } Execute 4th Execute 2nd Execute 1st Execute 3rd

while Loop Syntax Initialization expression; while (test-expression) { statements; : update expressions; }

do-while Loop Always execute at least once Syntax Initialization expression; do { statements; : update expressions; } while (test-expression)

JUMP STATEMENT goto statement break statement continue

goto STATEMENT goto label; --- label : Transfer the program control to specified place by a label Syntax goto label; --- label : label is a user supplied identifier and can appear either before or after goto.

break STATEMENT Enables a program to skip over part of the code while (test exprsn) { statement 1; if (val >2000) break; : statement2 } statement3; for(inilialize; test- exprsn; update) { statement 1; if (val >2000) break; : statement2 } statement3; do { statement 1; if (val >2000) break; : statement2 } while(test exprsn) statement3;

continue STATEMENT Instead forcing termination, it forces the next iteration of the loop to take place, skipping any code in between while (test exprsn) { statement 1; if (val >2000) continue; : statement2 } statement3; for(inilialize; test- exprsn; update) { statement 1; if (val >2000) continue; : statement2 } statement3; do { statement 1; if (val >2000) continue; : statement2 } while(test exprsn) statement3;

Diagrammatic representation Flow of control Statements Selection Statements Iteration Statements Jump Statement if stme nts switch stmen ts for stmen ts while stmen ts do-while stmen ts goto stmen ts break stmen ts continue stmen ts