Docsity

CSIS 110 Lecture 15: Quiz Results and Discussion on Loops and Iteration in Java - Prof. Br, Study notes of Javascript programming

Toggle sidebar
bg1
CSIS 110 โ€“ Lecture 15
Quiz Results
Statistics
Possible: 25
Mean: 16.9
Std dev: 4.8
Median: 18
Max: 23
Distribution: <=15: 3, 15 to 19: 6, 20+: 4
Let's look at examples from the last lab
Chapter 6: Iteration
Last time we looked at the while statement.
while ( <boolean expression> )
statement
And we looked at a couple of programs that included the while statement:
NumberAverage.java and Interest.java.
Flow chart.
Let's look at memory as this loop executes
Remember, main steps of the loop:
preparation
while situation of interest is true {
loop processing
prepare for next iteration
}
What are the values of variables after the loop executes?
Infinite loops: if you don't modify the values of the variables used in the boolean
expression correctly, your loop will never stop.
while ( number > 0 ) {
sum = sum + number;
pf2

Partial preview of the text

Download CSIS 110 Lecture 15: Quiz Results and Discussion on Loops and Iteration in Java - Prof. Br and more Study notes Javascript programming in PDF only on Docsity!

CSIS 110 โ€“ Lecture 15

Quiz Results Statistics Possible: 25 Mean: 16. Std dev: 4. Median: 18 Max: 23 Distribution: <=15: 3, 15 to 19: 6, 20+: 4 Let's look at examples from the last lab Chapter 6: Iteration Last time we looked at the while statement. while ( ) statement And we looked at a couple of programs that included the while statement: NumberAverage.java and Interest.java. Flow chart. Let's look at memory as this loop executes Remember, main steps of the loop: preparation while situation of interest is true { loop processing prepare for next iteration } What are the values of variables after the loop executes? Infinite loops: if you don't modify the values of the variables used in the boolean expression correctly, your loop will never stop. while ( number > 0 ) { sum = sum + number;

System.out.println( sum ); NOTE: When might you want a loop to run "forever"? Beware of the same types of errors that occur with if statements: don't put a ; after the boolean expression. Don't forget the {} *Operators +=, -=, =, /=, %= In our programs, we frequently use a variable, add a value to it, and assign the result back into the original variable: valueSum = valueSum + value; money = money * (1 + interest); This is a very common type of expression, so Java provides a shorthand operator for us valueSum += value; money = 1 + interest; // Also /=, -=, %= String s = ""; int j = 0; while ( j < 20 ) { s += ""; j++; } Lab Exercise In genetics, DNA is represented using the symbols A, G, T, and C. Develop a program that asks the user to enter a DNA sequence. Your program should display one of two messages: "That String represents a DNA sequence" "That is not a DNA sequence. The character at position is not one of A, G, T, or C." Your program may stop after it finds the first invalid character.