Download presentation
Presentation is loading. Please wait.
Published byRudolf Greene Modified over 9 years ago
1
Lecture 4: For Loops Announcements & Review Announcements Examples posted after lecture on schedule Discussion Section exercises on line before 9am Tuesdays Lab 2 Due Thursday 10pm Last Time: –Compilation –Scaffolding –print(): displays a value –println(): displays a value and moves cursor to the next line
2
Lecture 4: For Loops Today More on Beauty Analogy: Formatting Paragraphs Sequencing Analogy: a well constructed essay Note on punctuation: end your statements Repetition (i for iteration) for (int i = 0; i < 10; i++) { // your code here }
3
Lecture 4: For Loops Beauty /* Kathryn S McKinley * September 2005 * file: Song.java - a few lines from a good song * Song: All These Things That I’ve Done * Band: The Killers, Album: Hot Fuss */ public class Song { public static void main (String [] args) { System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”); }
4
Lecture 4: For Loops I’m Ugly /* Kathryn S McKinley * September 2005 * file: Song.java - a few lines from a good song * Song: All These Things That I’ve Done * Band: The Killers, Album: Hot Fuss */ public class Song { public static void main (String [] args) { System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”); }
5
Lecture 4: For Loops Paragraphs // song lines System.out.println(“You are going to bring yourself down”); System.out.println(“I’ve got soul, but I’m not a soldier. ”); System.out.println(“Yah yah, you got to help me out.”);
6
Lecture 4: For Loops Paragraphs // verse System.out.println(“You are going to bring yourself down”); //chorus System.out.println(“I’ve got soul, but I’m not a soldier. ”); //verse System.out.println(“Yah yah, you got to help me out.”);
7
Lecture 4: For Loops Can we do better? // verse System.out.println(“You are going to bring yourself down.”); //chorus System.out.println(“I’ve got soul, but I’m not a soldier. ”); //verse System.out.println(“Yah yah, you got to help me out.”);
8
Lecture 4: For Loops Yes! // verse System.out.println(“You are going to bring yourself down.”); //chorus for (int i =0; i < 10; i++) { System.out.println(“I’ve got soul, but I’m not a soldier. ”); } //verse System.out.println(“Yah yah, you got to help me out.”);
9
Lecture 4: For Loops For: Definite Loop Three parts for (i = 0; i < 99; i++) { // loop body } 1.Initialization 2.Test 3.Increment
10
Lecture 4: For Loops For: Definite Loop Three parts for (int i = 0; i < 99; i++) { // loop body in here } 1.Initialization - int i = 0; one time only 2.Test - if i < 99 then execute body every time 3.Increment - i++ add 1 to the value of I every time
11
Lecture 4: For Loops BlueJ Examples
12
Lecture 4: For Loops Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.