The nested repetition control structures & Continue 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

Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
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.
Repeating Actions While and For Loops
1 Lecture 11:Control Structures II (Repetition) (cont.) Introduction to Computer Science Spring 2006.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 Parts of a Loop (reminder) Every loop will always contain three main elements: –Priming: initialize your variables. –Testing: test against some known.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
Chapter 5: Control Structures II (Repetition)
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Week 3 - Friday.  What did we talk about last time?  Bitwise practice  Precedence  Control flow.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
C++ for Engineers and Scientists, Third Edition1 Objectives In this chapter, you will learn about: Basic loop structures while loops Interactive while.
LOOPS In the Name of Allah The Most Merciful The Most Compassionate LOOPS
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
Control Structures II (Repetition). Objectives In this chapter you will: Learn about repetition (looping) control structures Explore how to construct.
1. Agenda for loop Short-handed notation How to use break and continue 2.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 4 - Program Control Outline 4.1Introduction 4.2The Essentials of Repetition 4.3Counter-Controlled.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
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.
Nested for loops.
Printing with for Loops To print a character multiple times, use a for loop. for (int j = 1; j
Repetition Repetition allows you to repeat an operation or a series of operations many times. This is called looping and is one of the basic structured.
PGT C Programming1 Week 4 – Repetition Structures / Loops.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
LOOPS IN ‘C’ PROGRAMMING. V ERY O FTEN, Y OU W ILL W ANT TO D O S OMETHING M ORE T HAN O NCE HA.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
Chapter 5: Looping. Using the while Loop Loop – A structure that allows repeated execution of a block of statements Loop body – A block of statements.
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.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Control Structures (Repetition structure) Jump Statements
Lecture 4b Repeating With Loops
Chapter 4 Repetition Statements (loops)
REPETITION CONTROL STRUCTURE
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Lecture 7: Repeating a Known Number of Times
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
CS1010 Programming Methodology
Branching Constructs Review
( Iteration / Repetition / Looping )
Control Structures Lecture 7.
INC 161 , CPE 100 Computer Programming
Looping.
For Loops October 12, 2017.
Lec 7.
Chapter 8 The Loops By: Mr. Baha Hanene.
Chapter 4 - Program Control
Design and Implementation
Chapter 8: More on the Repetition Structure
Week 6 CPS125.
UMBC CMSC 104 – Section 01, Fall 2016
More Loops Topics Counter-Controlled (Definite) Repetition
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Statements in C Programming
More Loops Topics Counter-Controlled (Definite) Repetition
Building Java Programs
More Loops Topics Counter-Controlled (Definite) Repetition
More Loops Topics Counter-Controlled (Definite) Repetition
Repetition Structures
More Loops Topics Counter-Controlled (Definite) Repetition
Programming Fundamental
More Loops Topics Counter-Controlled (Definite) Repetition
break & continue Statements
Presentation transcript:

The nested repetition control structures & Continue Statements

What is nested loop?? A loop inside the body of another loop is called nested loop. The loop that contains another loop in its body is called outer loop. The loop used inside the body of outer loop is called inner loop.

Syntax Outer loop { statements; Inner loop body of inner loop }

Flowchart of nested loop condition for outer loop False True Condition for inner loop False True Body of inner loop

Example void main() { int u, i; u=1; while (u<=3) printf(“%d”); for(i=1; i<=2; i++) printf(“I love pakistan”); u= u+1; }

Infinite loop sometimes called an endless loop Infinite loop is a piece of coding that lacks a functional exit so that it repeats indefinitely. Usually, an infinite loop results from a programming error for example, where the conditions for exit are incorrectly written. Intentional uses for infinite loops include programs that are supposed to run continuously.

The continue statement The continue statement can be used in the body of any loop structure. statement is executed, it skips the remaining of loop.

Syntax & Example Syntax: continue; Example: int x=1; do { printf(“Welcome”); ++x; printf(“Karachi”); }while (x<=5);

void main() { int u, i; for(u=5; u>=1; u--) for(i=1; i<=u; i++) { printf(“*”); } printf(“\n”); } getch();

Program task1… Write a program that displays the following output using the nested for loop. ***** **** *** ** *

Program task2… Write a program that displays the following output using the nested for loop. 1 2 3 4 5 2 4 6 8 10 3 6 9 12 15 4 8 12 16 20 5 10 15 20 25

void main() { int u, i; u=1; while(u>=5) i=1; while(i<=u) printf(“%d\t”, u*i++); u++; } getch();

Program task3… Write a program that displays the following output using the nested for loop. 1 1 4 1 4 9 1 4 9 16 1 4 9 16 25

void main() { int u, i; u=1; while(u<=5) i=1; while(i<=u) printf(“%d\t”, i*i); i++; } printf(“\n”); u++; getch();