 An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are.

Slides:



Advertisements
Similar presentations
Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 3 Programming In C++, Lecture 3 By Umer Rana.
CS0007: Introduction to Computer Programming
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
CHAPTER 5: Repetition Control Structure. Objectives  To develop algorithms that use DOWHILE and REPEAT.. UNTIL structures  Introduce a pseudocode for.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
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.
Do Loops A Do..Loop terminates based on a condition that is specified Execution of a Do..Loop continues while a condition is True or until a condition.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Introduction to Computers and Programming for Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to.
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand basic loop concepts: ■ pretest loops and post-test loops ■ loop.
1 Fall 2008ACS-1903 Ch 4 Loops and Files while loop do-while loop Other topics later on …
Lecture Review (If-else Statement) if-else statement has the following syntax: if ( condition ) { statement1; } else { statement2; } The condition.
“Here we go Loop de Loo” (Looping) So far you have learned (I hope) some decision making C++ control structures: *if (condition) else *if (condition) else.
11 Chapter 4 LOOPS AND FILES. 22 THE INCREMENT AND DECREMENT OPERATORS To increment a variable means to increase its value by one. To decrement a variable.
 Decision making statements Decision making statements if statement if...else statement Nested if...else statement (if...elseif....else Statement) 
Programming with C# Iteration LECTURE 3. Summary of last lecture SequenceSelectionif and switch statementsCastingRandom.
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.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
Computer Science Department LOOPS. Computer Science Department Loops Loops Cause a section of your program to be repeated a certain number of times. The.
1. Agenda for loop Short-handed notation How to use break and continue 2.
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,
Lecture 4: Calculating by Iterating. The while Repetition Statement Repetition structure Programmer specifies an action to be repeated while some condition.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Flow Control (for) Outline 4.1Introduction 4.2The.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Looping Construct or Statements. Introduction of looping constructs In looping,a sequence of statements are executed until some condition for termination.
ECE 103 Engineering Programming Chapter 18 Iteration Herbert G. Mayer, PSU CS Status 7/19/2015 Initial content copied verbatim from ECE 103 material developed.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Computer Programming Control Structure
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Looping ROBERT REVAES. Logical Operators  && AND  Both have to be true for it to evaluate to be true.  || OR  One or the other has to be true for.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
For Loop Lecture No 8. Definition In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for.
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.
BY ILTAF MEHDI (MCS, MCSE, CCNA)1. INSTRUCTOR: ILTAF MEHDI (MCS, MCSE, CCNA, Web Developer) BY ILTAF MEHDI (MCS, MCSE, CCNA)2 Chapter No: 04 “Loops”
Course Title Object Oriented Programming with C++ Course instructor ADEEL ANJUM Chapter No: 04 loops 1 BY ADEEL ANJUM ( MSc - cs, CCNA, WEB DEVELOPER )
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
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.
Chapter 6. Loops A control structure that causes a statement or group of statements to be executed repeatedly There are 3 types of loops –while –for –do.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Module 6 – Decision Control Statements Objectives  Understands Increment/Decrement operators, Conditional and special operators in C  Understands significance.
Week 3.  TO PRINT NUMBERS FROM 1 TO 20  TO PRINT EVEN NUMBERS FROM 1 TO 20 2.
The Repetition control structure using while loop.
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.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
CHAPTER 4 REPETITION STRUCTURES 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Asma Alosaimi.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Control Structures (Repetition structure) Jump Statements
Lecture 7: Repeating a Known Number of Times
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Chapter 6 Repetition Objectives ❏ To understand basic loop concepts:
For Loops October 12, 2017.
Chapter 4 Repetition Structures
Arrays, For loop While loop Do while loop
LRobot Game.
Computer Science Core Concepts
Alternate Version of STARTING OUT WITH C++ 4th Edition
ECE 103 Engineering Programming Chapter 18 Iteration
Repetition Statements (Loops) - 2
PROGRAM FLOWCHART Iteration Statements.
Statements in C Programming
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Programming Fundamental
Presentation transcript:

 An instruction or group of instructions.  Computer executes program repeatedly for specified number of times. Or until some terminating conditions are satisfied. 3

 There are two types of loop. A. Determinant loop or counter loop: Extremely powerful loop. This loop is used, when the number of executions or iteration is known. Used in programs like print “university of swat” 5 times. Etc. 2

B. Undeterminant loop or controlled loop: Its Execution depends upon the condition either true or false. The number of iteration is not known before the operation. While and do while loops are used here. 3

 There are three methods to loop a program. A.Using For loop or (For statement). B.Using while loop or (while statement). C.Using do while loop or (do while statement). 4

 The popular and mostly used loop.  It is determinant loop.  It checks the condition before execution. Which means that it is pretest loop. 5

A.INITIALIZATION : Means to assign value for variable to initialize the loop. i.e (azr=11). B.CONDITION : Test the condition either it reach the desire number of execution or not. i.e (azr<=20). C.EXPRESSION UPDATE : It increases the loop counter as much it executes. i.e (azr=11+1). 6

{ azr=11,azr for (azr=11,azr<=20,azr=11+1) expression update initialization condition { Body of the loop } 7

#include void main ( ) { int azr; clrscr ( ); for(azr=5;azr<=45;azr=5+1) { printf(“%d\n”,azr); } getch(); } 8

Then we put “if” statement after the “for” statement. i.e  to get even numbers: { For (initialization ;condition ; expression update) if (azr%2==0); }  to get odd numbers the if statement should be if (azr%2!=0). 9

#include void main( ) { int amb; clrscr( ); { for (amb=20;amb<=40;amb=amb+1) if (amb%2==0); } printf (“%d\n”,amb); getch(); } 10

#include void main( ) { int X; clrscr( ); { for (X=9;X<=35;X=X+1) if (X%2!=0); } printf (“%d\n”,X); getch(); } 11