Repetition Statements

Documents pareils
Instructions Mozilla Thunderbird Page 1

Application Form/ Formulaire de demande

Utiliser une WebCam. Micro-ordinateurs, informations, idées, trucs et astuces

Gestion des prestations Volontaire

Formulaire de candidature pour les bourses de mobilité internationale niveau Master/ Application Form for International Master Scholarship Programme

Compléter le formulaire «Demande de participation» et l envoyer aux bureaux de SGC* à l adresse suivante :

4. Outils pour la synchronisation F. Boyer, Laboratoire Lig

Dans une agence de location immobilière...

Faits saillants et survol des résultats du sondage

Once the installation is complete, you can delete the temporary Zip files..

IDENTITÉ DE L ÉTUDIANT / APPLICANT INFORMATION

Créé par Goldfing & Pblabla Créé le 02/05/ :49:00. Guide pour la déclaration d impôt

THE FRENCH EXPERIENCE 1

Contents Windows

Formulaire de candidature pour les bourses de mobilité internationale niveau Master/ Application Form for International Master Scholarship Program

Comprendre l impact de l utilisation des réseaux sociaux en entreprise SYNTHESE DES RESULTATS : EUROPE ET FRANCE

MODERN LANGUAGES DEPARTMENT

Guide d'installation rapide TFM-560X YO.13

Cours de didactique du français langue étrangère (*) French as a foreign language (*)

Règlement sur le télémarketing et les centres d'appel. Call Centres Telemarketing Sales Regulation

accidents and repairs:

Paxton. ins Net2 desktop reader USB

Practice Direction. Class Proceedings

BNP Paribas Personal Finance

ANGULAR JS AVEC GDE GOOGLE

I. Programmation I. 1 Ecrire un programme en Scilab traduisant l organigramme montré ci-après (on pourra utiliser les annexes):

Module Title: French 4

PeTEX Plateforme pour e-learning et expérimentation télémétrique

La Routine Quotidienne. Le docteur se lave les mains

Programme Compte bancaire (code)

MEMORANDUM POUR UNE DEMANDE DE BOURSE DE RECHERCHE DOCTORALE DE LA FONDATION MARTINE AUBLET

MELTING POTES, LA SECTION INTERNATIONALE DU BELLASSO (Association étudiante de lʼensaparis-belleville) PRESENTE :

EN UNE PAGE PLAN STRATÉGIQUE

Archived Content. Contenu archivé

Lesson Plan Physical Descriptions. belle vieille grande petite grosse laide mignonne jolie. beau vieux grand petit gros laid mignon

Configurer la supervision pour une base MS SQL Server Viadéis Services

I. COORDONNÉES PERSONNELLES / PERSONAL DATA

I>~I.J 4j1.bJ1UlJ ~..;W:i 1U

Exercices sur SQL server 2000

WiFi Security Camera Quick Start Guide. Guide de départ rapide Caméra de surveillance Wi-Fi (P5)

Judge Group: P Title: Quel est meilleur: le compost ou le fertilisant chimique? Student(s): Emma O'Shea Grade: 6

calls.paris-neuroscience.fr Tutoriel pour Candidatures en ligne *** Online Applications Tutorial

TABLE DES MATIERES A OBJET PROCEDURE DE CONNEXION

that the child(ren) was/were in need of protection under Part III of the Child and Family Services Act, and the court made an order on

APPENDIX 6 BONUS RING FORMAT

POLICY: FREE MILK PROGRAM CODE: CS-4

et Active Directory Ajout, modification et suppression de comptes, extraction d adresses pour les listes de diffusion

Plan du cours. Historique du langage Nouveautés de Java 7

Instructions pour mettre à jour un HFFv2 v1.x.yy v2.0.00

English Q&A #1 Braille Services Requirement PPTC Q1. Would you like our proposal to be shipped or do you prefer an electronic submission?

Comment calculer une moyenne journalière de l irradiance avec excel 2007? How to calculate a daily average amount of irradiance with Excel 2007?

F-7a-v3 1 / Bourses de mobilité / Mobility Fellowships Formulaire de demande de bourse / Fellowship Application Form

Confirmation du titulaire de la carte en cas de contestation de transaction(s) Cardholder s Certification of Disputed Transactions

Bienvenue au séminaire HP Service Anywhere Mardi 11 février 2014

If you understand the roles nouns (and their accompanying baggage) play in a sentence...

Directions Marketing : réussir vos challenges stratégiques et opérationnels d aujourd hui

Stakeholder Feedback Form January 2013 Recirculation

ÉTUDES MÉDICALES DE PREMIER CYCLE

Frequently Asked Questions

Provincial Mathematics Assessment at Grade 3 French Immersion. Sample Assessment

Fiche produit ifinance v4

The new consumables catalogue from Medisoft is now updated. Please discover this full overview of all our consumables available to you.

How to Login to Career Page

JSIam Introduction talk. Philippe Gradt. Grenoble, March 6th 2015

Java Licence Professionnelle CISII,

INTRODUCTION A JAVA. Fichier en langage machine Exécutable

SERVEUR DÉDIÉ DOCUMENTATION

DOCUMENTATION - FRANCAIS... 2

Contrôle d'accès Access control. Notice technique / Technical Manual

1. Structure d un programme C. 2. Commentaire: /*..texte */ On utilise aussi le commentaire du C++ qui est valable pour C: 3.

Outils d'analyse de la sécurité des réseaux. HADJALI Anis VESA Vlad

Institut français des sciences et technologies des transports, de l aménagement

TD3: tableaux avancées, première classe et chaînes

Formulaire d inscription (form also available in English) Mission commerciale en Floride. Coordonnées

Deadline(s): Assignment: in week 8 of block C Exam: in week 7 (oral exam) and in the exam week (written exam) of block D

Dates and deadlines

Dis où ces gens vont d après les images / Tell where these people are going based on the pictures.

Le Cloud Computing est-il l ennemi de la Sécurité?

Le passé composé. C'est le passé! Tout ça c'est du passé! That's the past! All that's in the past!

Logitech Tablet Keyboard for Windows 8, Windows RT and Android 3.0+ Setup Guide Guide d installation

If the corporation is or intends to become a registered charity as defined in the Income Tax Act, a copy of these documents must be sent to:

«Rénovation des curricula de l enseignement supérieur - Kazakhstan»

AMENDMENT TO BILL 32 AMENDEMENT AU PROJET DE LOI 32

Qualité et ERP CLOUD & SECURITY (HACKING) Alireza MOKHTARI. 9/12/2014 Cloud & Security

LMI 2. Programmation Orientée Objet POO - Cours 9. Said Jabbour. jabbour@cril.univ-artois.fr


RULE 5 - SERVICE OF DOCUMENTS RÈGLE 5 SIGNIFICATION DE DOCUMENTS. Rule 5 / Règle 5

Principe de TrueCrypt. Créer un volume pour TrueCrypt

Programmer en JAVA. par Tama

Garage Door Monitor Model 829LM

setting the scene: 11dec 14 perspectives on global data and computing e-infrastructure challenges mark asch MENESR/DGRI/SSRI - France

4. Groupement d objets

MEMORANDUM POUR UNE DEMANDE DE BOURSE DE RECHERCHE DOCTORALE DE LA FONDATION MARTINE AUBLET

Notice Technique / Technical Manual

ONTARIO Court File Number. Form 17E: Trial Management Conference Brief. Date of trial management conference. Name of party filing this brief

Les Portfolios et Moodle Petit inventaire

DOCUMENTATION - FRANCAIS... 2

8. Cours virtuel Enjeux nordiques / Online Class Northern Issues Formulaire de demande de bourse / Fellowship Application Form

Support Orders and Support Provisions (Banks and Authorized Foreign Banks) Regulations

Transcription:

Repetition Statements Recitation 02/20/2009 CS 180 Department of Computer Science, Purdue University

Announcement Grades are out: Project 2, 3 Lab 2, 3, 4, 5 Project 4 is due on Feb 25 th

Syntax for Three Forms of Loops while loop while ( <boolean expression> ) <statement block> do-while loop do <statement> while ( <boolean expression> ) ; for loop for ( <initialization>; <boolean expression>; <increment> ) <statement> 3

Control Flow of while Boolean Expression while ( number <= 100 ) sum = sum + number; previous statement; int sum = 0, number = 1 number = number + 1; Statement (loop body) number <= 100? false true sum = sum + number; number = number + 1; next statement; 4

Control Flow of do-while do Statement (loop body) previous statement; sum += number; number++; int sum = 0, number = 1 while ( number <= 100 ); Boolean Expression sum += number; number++; number <= 100? true false next statement; 5

Control flow of for Initialization Boolean Expression Increment previous statement; for ( number=1,sum=0 ; number<=100 ; number++ ) sum += number; number=1,sum=0; number<=100? Statement (loop body) false next statement; true sum += number; number++; 6

Choosing a Loop If you know how many times the loop will be iterated, use a for loop. If you don t know how many times the loop will be iterated, but it could be zero, use a while loop it will be at least once, use a do-while loop. 7

Example 1 The charat( int ) method of the String class returns the character at the given index of an instance. public String somemeth1( String str ) String result = ""; for ( int index = str.length() - 1; index >= 0; --index ) result += str.charat( index ); return result; What is the result of: somemeth1( "somewhere i have never traveled" ) 8

Example 2 public void somemeth2() String name = ""; Scanner keyboard = new Scanner( System.in ); do System.out.print( "Please enter a name or \"quit\" to exit: " ); name = keyboard.next(); System.out.println( "Howdy "+name+"!" ); while (!name.equals( "quit" ) ); How does the above compare to using a while loop? Is a for loop appropriate? 9

Example 3 public void somemeth3() String name = ""; Scanner keyboard = new Scanner( System.in ); while ( true ) System.out.print( "Please enter a name or \"quit\" to exit: " ); name = keyboard.next(); if (!name.equals( "quit" ) ) System.out.println( "Howdy "+name+"!" ); else break; Does the above loop terminate? How does this compare to somemeth2? 10

Example 4 public void somemeth4() String name = ""; Scanner keyboard = new Scanner( System.in ); S.o.p( "Please enter a name or \"quit\" to exit: " ); name = keyboard.next(); while (!name.equals("quit") ) S.o.pln( "Howdy "+name+"!" ); S.o.p( "Please enter a name or \"quit\" to exit: " ); name = keyboard.next(); Notice that this has a cleaner flow than example 3. Priming the loop can avoid extra cases and bugs. 11

Example 5 public void somemeth5() Scanner keyboard = new Scanner( System.in ); while ( true ) switch( keyboard.nextint() ) case 0: case 1: case 2: System.out.println( "In here" ); break; case 3: case 4: case 5: System.out.println( "Somewhere else" ); continue; System.out.println( "After Switch" ); How does this loop behave when 7 is entered? 3? 0? 12

Example 6 public void somemeth6() for ( int i = 0; i < 5; ++i ) for ( int j = 5-i; j > 0; --j ) System.out.print( "*" ); System.out.println(); Notice how loops within loops can interact. What does each loop correspond to? Notice how using a table can help you execute this manually. 13

Example 7 public void somemeth7() for ( int i = 0; i < 5; ++i ) for ( int j = 5-i; j > 0; --i ) System.out.print( "*" ); System.out.println(); What happens here? Where is the mistake? 14

Example 8 public void somemeth8() for ( int i = 0; i < 5; ++i ) for ( int j = 5-i; j > 0; --j ) System.out.print( "*" ); --i; System.out.println(); How does this behave? 15

Example 9 public void somemeth9() int sum = 0; for (int count=1; count<5; count++) System.out.println( Count: + count); sum = sum + count; System.out.println( Sum: + sum); How does this behave? What have we forgotten? 16

Example 10 public void somemeth10() int sum = 0; for (int count=1; count<5; count++); System.out.println( Count: + count); sum = sum + count; System.out.println( Sum: + sum); How about this one? 17

Quiz What is the difference between break and continue? Are the different forms of loops equivalent? 18