We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement.

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

5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
LOOP / REPETITION while loop. for loop do/while loop We assume that loops are not meant to be infinite. That is, there should always be a way out of the.
Topic 03 Control Statements Programming II/A CMC2522 / CIM2561 Bavy Li.
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
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.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
CLASS XI By Sumita Arora
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
UNIT II Decision Making And Branching Decision Making And Looping
Computer Science Department Relational Operators And Decisions.
Chapter 3 Control Flow Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
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)
Additional Control Structures. Chapter 9 Topics Switch Statement for Multi-way Branching Do-While Statement for Looping For Statement for Looping Using.
CPS120: Introduction to Computer Science Decision Making in Programs.
1 Chapter 9 Additional Control Structures Dale/Weems.
Chapter 7 Additional Control Structures. 2 2 void GetYesOrNo (/* out */ char& response) // Inputs a character from the user // Postcondition: response.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
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.
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Control structures Algorithm Development Conditional Expressions Selection Statements 1.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 4 Control Structures C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
CPS120 Introduction to Computer Science Iteration (Looping)
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.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
Chapter : 9 Control Statements Control Flow: A control flow Statement regulates the order in which statements get executed. F Flow-order in which the computer.
Statements
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Control Flow Statements
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.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
COMP Loop Statements Yi Hong May 21, 2015.
LECTURE # 8 : REPETITION STATEMENTS By Mr. Ali Edan.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Looping Increment/Decrement Switch. Flow of Control Iteration/Switch Statements.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Chapter 4 Repetition Statements Program Development and Design Using C++, Third Edition.
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.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
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.
Computer Programming -1-
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Branching statements.
REPETITION CONTROL STRUCTURE
LESSON 4 Decision Control Structure
Decisions Chapter 4.
Ch 7: JavaScript Control Statements I.
Arrays, For loop While loop Do while loop
3 Control Statements:.
Chapter 2.2 Control Structures (Iteration)
PROGRAM FLOWCHART Selection Statements.
Programming Fundamental
Presentation transcript:

We have to discuss following:-  Statements  Statement flow control  Selection statement  Iteration statement

Statements are the instruction given to the computers to perform any kind of action.  Compound Statement(Block) A compound statement in C++ is a sequence of statement enclosed by pair of braces{ }. For instance, { statement1; statement2; : }

In program, statement may be executed sequently, selectively or iteratively. Sequence. The sequence construct means the statement are being executed sequentially. This represent the default flow of statement (see fig 1) (fig 1)

Selection.The selection construct means the execution of statement(s) depending upon a condition test. (see fig2) (fig 2)

Iteration. The iteration construct means repetition of set-of – statement depending upon condition-test.

The selection statement allow to choose the set-of-instruction for execution depending upon an expression truth value.C++ provide two type of selection statement: 1. If and 2. Switch.

‘if’ is called single selection structure because it select or ignore a single action. Syntax(general form):- if(condition) { c++ expression or statement ; }

This type of structure is called double selection structure because it select between two different action. If the action is true that it will print true part and if action is false then it will print false part. Syntax:- if(condition) { c++ expression or statement ; } else { c++ expression or statement ; }

A nested if is an if that has another if in its if’s body or in its else’s body. Syntax :- if(condition ) { c++ expression ; } if(condition ) { c++ expression ; } else { c++ expression ; } else { c++ expression ; }

This selection statement successively test the value of an expression against a list of integer or character constant. When a match is found, the statement associated with that constant are executed. Syntax:- switch(expression) {case constant 1: c++ statement 1; break ; case constant 2:c++ statement 2; break; : case constant n: c++ statement n; break; }

Example of if Void main() { int grade; Cout<<”Enter the grade”; Cin>>grade; If (grade>=60) { Cout<<”pass”; }. getch () } #include Example of if -else Void main() { int age; Cout<<”Enter the age”; Cin>>age; If (age>=60) { Cout<<”Eligible”; }.else { Cout<<“Not”; }. getch (); } #include

Example of nested-if Void main() { float a,b,Result; Char ch; Cout<<”Enter the number 1:”; Cout<<”Enter the number 2:”; Cin>>a>>b; Cin>>ch;.. if (ch==‘-’) Result=a-b;.else if (ch==‘+’) Result=a+b;.. else { Cout<<“Wrong entry”; } Cout<<Result;. getch (); } #include Example of switch Void main() { int grade; Cout<<”Enter the grade in marks:”; Cin>>grade; switch (grade) { Case 90 :cout<<“A”; break; Case 80:cout<<“A”; break; Case 70 :cout<<“A”; break; Case 50 :cout<<“A”; break; Case 40 :cout<<“A”; break; default; } Cout<< “Wrong Entry”;. getch (); } #include

The iteration statement allows a set of instruction to be perform repeatedly until a certain condition is felled. It is also known as Loop’s. Loops are of four types that is: For loop While loop Do-while loop Nested loop

1)For loop is easiest to understand of the loops. All its loop-control element are gathered in one place, while in other loop construction of c++,they are scattered about the program. Syntax :- for (initialization expression(s); test-expression; update expression(s)) { c++ statement ; }

2)While loop is an entry controlled loop. The loop iterates while the expression evaluates to true. When expression become false, the program control passes to the line after the loop-body code. Syntax :- while (condition) { c++ statement }

3)The do-while loop is an exit-controlled loop i.e., it evaluate its test expression at the bottom of the loop after executing its loop-body statement. It means that a do-while loop always execute at least once. Syntax:- do { c++ statement; } while(test-expression);

4)A loop may contain another loop in its body. This form is known as nested loop. Syntax :- for (initialization expression 1; test-expression 1; update expression 1) { c++ statement ; //outer loop for (initialization expression 2; test-expression 2; update expression 2) c++ statement; //inner loop }

Example of for loop Void main() { int i;.. for (i=10;i<=10;i++) { Cout<<“\n”<<i; }. getch (); } #include Example of nested loop Void main() { int i,j;.. for (i=1;i<5;i++) Cout<<“\n”; for (j=1;j<i;j++) Cout<<“*”;. getch (); } #include

Example of while loop Void main() { int i=1;.. while (i<=10) { Cout<<i; } i++;. getch (); } #include Example of do-while loop Void main() { int i=1; do { Cout<<i; } i++; while(i<=10). getch (); } #include

Presented By:- Name : Shakti Prakash Class: 11 th Section: ‘B’ Roll Number : 11 Subject : Computer Science Topic :Flow Of Control