Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.

Slides:



Advertisements
Similar presentations
Karel – Chapter 6 Instructions That Repeat
Advertisements

Looping Structures: Do Loops
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.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Looping while … do …. Condition Process 2 Process 1 Y Repeated Loop.
Building Java Programs
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Sentinel Logic Assumes while loops and input statements.
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
Chapter 4: Control Structures II
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
Using Shortcut Arithmetic Operators Accumulator: A variable that is used to total. Its value is repeatedly increased by some amount. Java provides shortcuts.
More While Loop Examples CS303E: Elements of Computers and Programming.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
1 while loops. 2 Definite loops definite loop: A loop that executes a known number of times.  The for loops we have seen so far are definite loops. We.
For loops in programming Assumes you have seen assignment statements and print statements.
Topic 14 while loops and loop patterns Copyright Pearson Education, 2010 Based on slides bu Marty Stepp and Stuart Reges from
Loops  Did you get the point behind a loop?  Why is there a need for loops? Code JunkiesLoops 1.
Building java programs, chapter 5 Program logic and indefinite loops.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Loops and Simple Functions CS303E: Elements of Computers and Programming.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 4.1, 5.1.
Building Java Programs Program Logic and Indefinite Loops.
PGT C Programming1 Week 4 – Repetition Structures / Loops.
CPSC 233 Tutorial 5 February 2 th /3 th, Java Loop Statements A portion of a program that repeats a statement or a group of statements is called.
1 BUILDING JAVA PROGRAMS CHAPTER 5 PROGRAM LOGIC AND INDEFINITE LOOPS.
1 Building Java Programs Chapter 5 Lecture 5-1: while Loops, Fencepost Loops, and Sentinel Loops reading: 5.1 – 5.2.
Control Structures WHILE Statement Looping. S E Q C E N U E REPITITION …a step or sequence of steps that are repeated until some condition is satisfied.
Categories of loops definite loop: Executes a known number of times.
CSc 110, Autumn 2017 Lecture 17: while Loops and Sentinel Loops
Chapter 5: Control Structures II
Chapter 5: Control Structures II
Lecture 4 - Loops UniMAP EKT120 Sem 1 08/09.
Week 4 – Repetition Structures / Loops
Week 4 – Chapter 3 Repetition.
Repetition-Counter control Loop
Programming Fundamentals
Repetition.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Loops CS140: Introduction to Computing 1 Savitch Chapter 4 Flow of Control: Loops 9/18/13 9/23/13.
CSc 110, Autumn 2016 Lecture 12: while Loops, Fencepost Loops, and Sentinel Loops Adapted from slides by Marty Stepp and Stuart Reges.
For Loops October 12, 2017.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Building Java Programs
Chapter 9 Control Structures.
CSc 110, Spring 2018 Lecture 16: Fencepost Loops and while loops
Topic 14 while loops and loop patterns
Chapter (3) - Looping Questions.
Building Java Programs
CS150 Introduction to Computer Science 1
Looping III (do … while statement)
Let’s all Repeat Together
Loops Prof.Gaikwad Varsha P. Information Technology Dept.
A LESSON IN LOOPING What is a loop?
Loop problem Write a method printLetters that prints each letter from a word separated by commas. For example, the call: printLetters("Atmosphere") should.
Building Java Programs
CIS 110: Introduction to Computer Programming
Building Java Programs
Introduction to Computer Science
Median Statement problems.
Repetition Statements (Loops) - 2
Statements in C Programming
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Presentation transcript:

Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times. Repeat these statements for each odd number between 5 and 27. indefinite loop: A loop where it is not easy to know how many times it will execute. Repeat these statements until the user types a valid integer. Repeat these statements while the number n is not prime. Repeat these statements until a factor of n is found.

The while loop statement The while loop is a new loop statement useful for writing indefinite loops. The while loop, general syntax: while (<condition>) { <statement(s)> ; } Example: int number = 1; while (number <= 200) { System.out.print(number + " "); number *= 2; OUTPUT: 1 2 4 8 16 32 64 128