Chapter 6 Study Guide

Chapter 6

Complete Study

Study Guide

\
What is a counter?
A variable used to count the number of times an event occurs.


What does this counter store?
int count = 15;count = count + 1;System.out.println(count);
16


What is counting in Java?
Process of incrementing(increasing a variable by a particular amount)


What are two ways we can write counters?
Count = Count +1;
Count +=1;


T/F: We can use other math operators with counters.
True


Understand simple counter outputs if given. For example, relook at question 2.
No answer needed. Add your own
notes here if needed.


What is an accumulator?
A variable used to keep a running sum


What is the difference between counters and accumulators?
Counters = count
Accumulators = sum


What are Loops?
Process used to repeat a set of statements


What are the difference between definite loops and indefinite loops?
Definite Loop

A loop that repeats a certain number of times

Indefinite Loop

A loop that repeats based on a condition (Boolean Expressions)

\
What is a for loop?
A definite loop structure that executes a set of statements a fixed number of times.


What is the syntax and example for a for loop?
for ( ; ; )

{



}

\
\
What is an increment?
Increments - increases the number by one.


T/F: For loops cannot work backwards.
False. They can be done backwards


T/F: For loops can be incremented by a counter.

True


Out of the two loops, what kind of loop is a while loop?
Indefinite Loop


What is a while loop?
Repeats while a condition is true
Will a while loop execute if initially false?
May never execute if the condition is initially false


What is the syntax and example for a while loop?
while ()

{



}

\
\
What is a do-while loop?
Alternate While Loop

Evaluated at the end of the loop

Executes once before the condition is evaluated.

\
What is the syntax and example for a do-while loop?
do

{



}

while ();

\
\
What is the difference between a while loop and do while loop?
Do/while loop will always execute at least once


What is an infinite loop?
A loop where the condition never evaluates to false.

Loop continues to run and will cause a run time error or cause the computer to appear to freeze.

\
Understand Syntax errors in general, loops, and infinite loops?
No answer needed. Add your own
notes here if needed.

\
What is a nested loop?
Loops where one loop is completely inside (nested) another loop.


What is the syntax and example for a nested loop?
for (outer = 1 ; outer
robot