SlideServe
Menu
Préférences
© SlideServe · v2026

Iteration

roza avatar
14 diapositives · 362 Views · Jul 31, 2014

Iteration. Robert Stumpf, Professor Computer Information Systems California State Polytechnic University Pomona. Iteration. Bohm and Jacopini Iteration Forms while loop for loop do while loop. Bohm and Jacopini.

Iteration - slide 1
01 / 14Iteration
1 / 17

Télécharger la présentation

Iteration
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Iteration Robert Stumpf, Professor Computer Information Systems California State Polytechnic University Pomona iteration

  2. Iteration • Bohm and Jacopini • Iteration • Forms • while loop • for loop • do while loop iteration

  3. Bohm and Jacopini • Bohm and Jacopini stated that a Structured program contains three constructs: 1. Sequence 2. Selection 3. Iteration • They proved this mathematically iteration

  4. Bohm and Jacopini • This time we are interested in the third construct • It is called iteration which means do again • Its basic form is the while loop • The other forms are convenient but can be simulated if not present iteration

  5. Iteration • Iteration means to repeat the process • A while loop has the test at the beginning Question resulting in a boolean response { Process to be repeated } • If question is true, repeat, if false exit loop iteration

  6. Iteration • A do while loop has the test at the end do{ Process to be repeated }Question resulting in a boolean response If question is true, repeat, if false exit loop iteration

  7. Forms • Basic While (without a block)int count = 0; while ( count < 3 ) System.out.println(count ++); • Not using a block is not very useful as only one statement is permitted iteration

  8. Forms • Basic While (with a block)int count = 0; while ( count < 3 ) { System.out.println(count); count++ } • Using a block is better • The question is asked at the beginning iteration

  9. Forms • Using ++ count ++;Is same ascount = count + 1; • count -- is also legal • Its precedence is at the first level along with ! and – (unary) iteration

  10. Forms • Basic For (without a block) for (int i=0; i < 3; i++ ) System.out.println(count); • The question still is asked at the beginning iteration

  11. Forms • Basic For (with a block)for (int i=0; i < 3; i++ ) { System.out.println(count); } • Using a block is better; why? iteration

  12. Forms • Do While char response;do { // code to input, process, and output is here response = JOptionPane.showInputDialog (“Enter N if done; Y if you wish to do it again” ); } while (response.charAt(0) = = ‘Y’); • Question is asked at the end iteration

  13. Summary • Java allows one to iterate three ways • while loop – test at the beginning • for loop – test at the beginning • do while loop– test at the end • The for loop is for convenience as there are many situations requiring one to count iteration

  14. Thank You • Java has Built in Constructs to facilitate Iteration • Any questions should be directed to Professor Robert Stumpf • Email: rvstumpf@csupomona.edu • Web Site:http://www.csupomona.edu/~rvstumpf iteration