A LESSON IN LOOPING What is a loop?

Slides:



Advertisements
Similar presentations
Chapter 7 - Iteration. Chapter Goals Program repitiation statements – or loops – with the for, while, and do-while statements Program repitiation statements.
Advertisements

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
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 (Part 1) Computer Science Erwin High School Fall 2014.
Visual Basic.NET BASICS Lesson 10 Do Loops. 2 Objectives Explain what a loop is. Use the Do While and Do Until loops. Use the InputBox function. Use the.
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.
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
Switch structure Switch structure selects one from several alternatives depending on the value of the controlling expression. The controlling expression.
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
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.
Flow of Control Loops – Chapter 3.2. Java Loop Statements: Outline the while Statement the do-while Statement the for Statement.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
Lecture 8: Choosing the Correct Loop. do … while Repetition Statement Similar to the while statement Condition for repetition only tested after the body.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
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,
Repetition Statements while and do while loops
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
COMP Loop Statements Yi Hong May 21, 2015.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Nested For Loops. First, the rules to these loops do not change. We are sticking one loop inside another. while(condition) { // loop body } do { // loop.
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.
Repetition Statements b Repetition statements allow us to execute a statement multiple times repetitively b They are often simply referred to as loops.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
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.
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.
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.
Computer Programming -1-
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Topic : While, For, Do-While Loop Guided By : Branch : Batch :
Lesson #5 Repetition and Loops.
Chapter 4 Repetition Statements (loops)
CS161 Introduction to Computer Science
Lesson #5 Repetition and Loops.
Week 4 – Chapter 3 Repetition.
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
Repetition.
Iterations Programming Condition Controlled Loops (WHILE Loop)
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
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.
For -G7 programing language Teacher / Shamsa Hassan Alhassouni.
Loop Control Structure.
Loops October 10, 2017.
Outline Altering flow of control Boolean expressions
Lesson #5 Repetition and Loops.
More Loops.
More Loops.
Loops A portion of a program that repeats a statement or a group of statements is called a loop. The statement or group of statements to be repeated is.
Chapter (3) - Looping Questions.
Unit 3 - The while Loop - Extending the Vic class - Examples
IPC144 Introduction to Programming Using C Week 3 – Lesson 2
Module 4 Loops.
Lec 4: while loop and do-while loop
Three Special Structures – Case, Do While, and Do Until
Week 6 CPS125.
Control Structures Part 1
Looping III (do … while statement)
Introduction to Computer Science
Lesson #5 Repetition and Loops.
PROGRAM FLOWCHART Iteration Statements.
CSCI 1100/1202 February 6, 2002.
statement. Another decision statement, , creates branches for multi-
Week 3 – Repetition (ctd.)
Presentation transcript:

A LESSON IN LOOPING What is a loop? A portion of a program that repeats a statement or group of statements

while statement (while-loop) TYPES OF LOOPS while statement (while-loop) Action that is coded in braces (body of the while loop) is repeated (in order) until the condition of the while loop is met. Repetition is called an iteration of the loop

CODING EXAMPLE How many greetings? Ask the user how many ‘hello’ statements they want to print and execute. Print ‘That’s All!’ when finished.

SYNTAX while(condition) { Insert code to repeat here }

EXAMPLE

TYPES OF LOOPS do while statement Similar to while statement, except that the loop body is always executed at least once. Do ‘this’ (at least once), while ‘this’ is true

Hello! Do you want another? CODING EXAMPLE Hello! Do you want another? Greet the user – ‘Hello!’, ask if they would like another greeting – input 1(yes) or 2(no)? Execute until user enters 2(no)

SYNTAX do { Insert code to repeat here }while(condition);

EXAMPLE