PROGRAM FLOWCHART Iteration Statements.

Slides:



Advertisements
Similar presentations
While loops.
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
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.
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
CS1061: C Programming Lecture 8: Repetition A. O’Riordan, 2004.
University of British Columbia CPSC 111, Intro to Computation 2009W2: Jan-Apr 2010 Tamara Munzner 1 Loops III Lecture 19, Wed Mar
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
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.
Copyright © Texas Education Agency, Computer Programming For Loops.
1 Fall 2008ACS-1903 Ch 4 Loops and Files while loop do-while loop Other topics later on …
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
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.
Repetition Statements.  Often it is necessary to repeat statements many times  Java has two ways of doing this  while statements  for statements.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
LOOPS In the Name of Allah The Most Merciful The Most Compassionate LOOPS
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,
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Repetition Statements while and do while loops
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
COMP 110 More loops Luv Kohli September 15, 2008 MWF 2-2:50 pm Sitterson
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.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
1 Fall 2009ACS-1903 Ch 4 Loops and Files while loop do-while loop for loop Other topics later on …
Catie Welsh February 9,  Friday - No Lab! ◦ Bring questions on Project 2  Lab 3 due on Friday 2.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING While Loop.
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
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.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
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.
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.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
Follow up from lab See Magic8Ball.java Issues that you ran into.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Chapter 9 Repetition.
Chapter 4 Repetition Statements (loops)
Loops in Java.
Control Structures.
CiS 260: App Dev I Chapter 4: Control Structures II.
Chapter 5 Repetition.
Arrays, For loop While loop Do while loop
Loop Control Structure.
Loops October 10, 2017.
Outline Altering flow of control Boolean expressions
Chapter 9 Control Structures.
LOOPS BY: LAUREN & ROMEO.
Repetition Control Structure
Chapter 8: More on the Repetition Structure
Control structures to direct program flow
Lab5 PROGRAMMING 1 Loop chapter4.
What output is produced by the following fragment?
A LESSON IN LOOPING What is a loop?
JavaScript: Control Statements II
Seating “chart” Front - Screen rows Back DOOR.
Repetition Statements (Loops) - 2
Building Java Programs
Learning Plan 4 Looping.
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.
CSCI 1100/1202 February 6, 2002.
Presentation transcript:

PROGRAM FLOWCHART Iteration Statements

Iteration Statements Loop structures allows a block of statements to be executed repeatedly. A boolean expression will be evaluated within the looping structure. If the structure is true, the block of statements called the loop body will be executed and then the boolean expression is evaluated again. The loop body will continue to execute as long as the expression is true. It will end when the boolean expression is false. 3 kinds of iteration statements: while do..while for loop

The while loop while loop is a statement or block of statements that is repeated as long as some condition is satisfied. syntax: while( condition ){ statement1; statement2; . . . } The statements inside the while loop are executed as long as the condition evaluates to true.

Example: int x = 0; while (x<10) { System.out.println(x); x++; } ---------------------------------------------------------------------------------------------- //infinite loop while(true) System.out.println(“hello”); ---------------------------------------------------------------------------------------------- //no loops // statement is not even executed while (false) System.out.println(“hello”);

The do…while loop do-while loop is similar to the while-loop statements inside a do-while loop are executed several times as long as the condition is satisfied The main difference between a while and do-while loop: The statements inside a do-while loop are executed at least once. syntax: do{ statement1; statement2; . . . }while(condition );

Example: int x = 0; do { System.out.println(x); x++; }while (x<10); ---------------------------------------------------------------------------------------------- //infinite loop do{ System.out.println(“hello”); } while (true); ---------------------------------------------------------------------------------------------- //one loop // statement is executed once do{ System.out.println(“hello”); }while (false);

The for loop for loop allows execution of the same code a number of times. syntax: for(initialization;condition;counter progression) { statement1; statement2; . . . } Where: initialization -initializes the loop variable. condition - compares the loop variable to some limit value. counter progression – an expression that increment or decrement the loop control variable.

Example: int i; for( i = 0; i < 10; i++ ){ System.out.println(i); } The code shown above is equivalent to the following while loop. int i = 0; while( i < 10 ){ System.out.print(i); i++;