DELHI PUBLIC SCHOOL TAPI

Similar documents
Prepared by: Shraddha Modi

Programming Fundamentals

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

CHAPTER 9 FLOW OF CONTROL

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

CHAPTER : 9 FLOW OF CONTROL

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

Looping statement While loop

REPETITION CONTROL STRUCTURE LOGO

Selection / making decision If statement if-else, if-else-if or nested if Switch Case

Unit 3 Decision making, Looping and Arrays

Loops and Files. Chapter 04 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz

MORE ON LOOPS IN JAVA

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

In this chapter you will learn:

Introduction. C provides two styles of flow control:


CHAPTER 2.2 CONTROL STRUCTURES (ITERATION) Dr. Shady Yehia Elmashad

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

Chapter 1. Principles of Object Oriented Programming

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Why Is Repetition Needed?

SELECTION STATEMENTS:

INTRODUCTION TO PROGRAMMING

BLUE PRINT SUBJECT: - COMPUTER SCIENCE(083) CLASS-XI. Unit Wise Marks

C++ Programming: From Problem Analysis to Program Design, Third Edition

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

C++ PROGRAMMING SKILLS Part 2 Programming Structures

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

OER on Loops in C Programming

Computers Programming Course 7. Iulian Năstac

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

C++ Programming: From Problem Analysis to Program Design, Fourth Edition. Chapter 5: Control Structures II (Repetition)

Understanding main() function Input/Output Streams

Introduction to the Java Basics: Control Flow Statements

Object Oriented Pragramming (22316)

LECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. Looping. ++ is the increment operator.

*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN

Object-Oriented Programming in Java

Chapter 5: Control Structures II (Repetition) Objectives (cont d.) Objectives. while Looping (Repetition) Structure. Why Is Repetition Needed?

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

All copyrights reserved - KV NAD, Aluva. Dinesh Kumar Ram PGT(CS) KV NAD Aluva

UIC. C Programming Primer. Bharathidasan University

Statements execute in sequence, one after the other, such as the following solution for a quadratic equation:

Accelerating Information Technology Innovation

Computer Programming: C++

Increment and the While. Class 15

1 Unit 8 'for' Loops

Control Structures of C++ Programming (2)

Instructor: SIR MUHAMMAD NAVEED Created by: ARSLAN AHMED SHAAD ( ) MUHAMMAD BILAL ( ) ISIT:

Name SECTION: 12:45 2:20. True or False (12 Points)

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

LECTURE NOTES ON PROGRAMMING FUNDAMENTAL USING C++ LANGUAGE

Pointers II. Class 31

CHAPTER 4 FUNCTIONS. 4.1 Introduction

Flow Control. CSC215 Lecture

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Loops! Loops! Loops! Lecture 5 COP 3014 Fall September 25, 2017

OOP THROUGH C++(R16) int *x; float *f; char *c;

YOLOP Language Reference Manual


Control Structures. Control Structures Conditional Statements COMPUTER PROGRAMMING. Electrical-Electronics Engineering Dept.

Programming Language. Functions. Eng. Anis Nazer First Semester

A SHORT COURSE ON C++

8. Control statements

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING Chapter 4: Repetition Control Structure

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

CS201 Some Important Definitions

Programming in C++ The manager of a company. Lecture Notes 6. Functions (Procedures) 4/24/2018. he he he. Does Does Does

The for Loop, Accumulator Variables, Seninel Values, and The Random Class. CS0007: Introduction to Computer Programming

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

Introduction to Programming I COS1511 School of Computing Revision Notes

Control Structures. Repetition (Loop) Structure. Repetition (Loop) Structure. Repetition (Loop) Structure. CS225: Slide Set 8: C++ Loop Structure

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

EP241 Computing Programming

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Islamic University of Gaza Computer Engineering Dept. C++ Programming. For Industrial And Electrical Engineering By Instructor: Ruba A.

COMPUTER PROGRAMMING LOOPS

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

V3 1/3/2015. Programming in C. Example 1. Example Ch 05 A 1. What if we want to process three different pairs of integers?

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

Structured Programming. Flowchart Symbols. Structured Programming. Selection. Sequence. Control Structures ELEC 330 1

C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

KENDRIYA VIDYALAYA SANGATHAN, GUWAHATI REGION HALF-YEARLY EXAMINATION-2015 CLASS XI : COMPUTER SCIENCE Time Allotted : 3 hrs. Max.

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Container Class and Integrators, Proxy Class EC6301-OOPS AND DATA STRUCTURES

UNIT- 3 Introduction to C++

Arrays. int Data [8] [0] [1] [2] [3] [4] [5] [6] [7]

C/C++ Programming Lecture 7 Name:

COMMON QUARTERLY EXAMINATION SEPTEMBER 2018

Transcription:

Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on. A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages Loop Architecture programming language provides the following type of loops to handle looping requirements.

There are 3 types of loops in language 1) while loop 2) for loop 3) -while loop while loop while loop can be address as an entry control loop. It is completed in 3 steps. 1) Variable initialization (e.g. int x=0; ) 2) Condition( e.g while( x<=10) ) 3) Variable increment or decrement (x++ or x-- or x=x+2 ) Syntax : variable initialization ; while (condition) statements ; Example of While Loop variable increment or decrement ; #include <iostream.h> #include<conio.h> // Local variable declaration: int a = 10; // while loop execution while( a < 20 ) cout << "value of a: " << a << endl; a++;

Output value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 Do While Loop Do While loop can be address as an exit control loop. In some situations it is necessary to execute body of the loop before testing the condition. Such situations can be handled with the help of -while loop. statement evaluates the body of the loop first and at the end, the condition is checked using while statement. In While loop if the condition is wrong still it will executed at once. General format of -while loop is, Syntax Example: Variable initialization; Increment/decrement; //optional Statement(s); while(condition); #include <iostream.h> #include<conio.h> // Local variable declaration: int a = 10; // while loop execution cout << "value of a: " << a << endl;

a++; while(a<20); Output value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19 For Loop for loop is used to execute a set of statement repeatedly until a particular condition is satisfied. we can say it an open ended loop. General format is, Syntax for(initialization; condition ; increment/decrement) statement-block; In for loop we have exactly two semicolons, one after initialization and second after condition. In this loop we can have more than one initialization or increment/decrement, separated using comma operator. for loop can have only one condition. Example #include<iostream.h> #include<conio.h> void main() clrscr(); cout<<"\n The first 10 integers are as follows :"<<endl; for(int i=1;i<=10;i++) cout<<" "<<i;

Output Jumping out of loop Sometimes, while executing a loop, it becomes necessary to skip a part of the loop or to leave the loop as soon as certain condition becomes true, that is jump out of loop. C language allows jumping from one statement to another within a loop as well as jumping out of the loop. 1) Break statement When break statement is encountered inside a loop, the loop is immediately exited and the program continues with the statement immediately following the loop. Example #include <iostream> // Declaring Local variable int count = 0; // loop execution cout << "Count : " << count << endl;

count++; if( count > 5) // Terminate the loop break; while( count < 20 ); 2) Continue statement The continue statement forces the next iteration of the loop to take place, skipping remaining code in between. 1. In the case of the for loop as soon as after the execution of continue statement, increment/decrement statement of the loop gets executed. After the execution of increment statement, condition will be checked. 2. In case of the while loop, continue statement will take control to the condition statement. 3. In case of the..while loop, continue statement will take control to the condition statement specified in the while loop. Example #include <iostream.h> #include <conio.h>

int count = 0; count++; if(count > 5 && count < 7) continue; cout << "Count : " << count << endl; while( count < 10 ); Output : Count : 1 Count : 2 Count : 3 Count : 4 Count : 5 Count : 7 Count : 8 Count : 9 Count : 10 In the above example, when count = 6 then both conditions become true and thus continue statement gets executed in that case.