Chapter 02 Summary
For loop - repeats when you know the number of times to repeat
for (statement to start the loop; condition that
evaluates to true or false; statement to run when the loop repeats)
{
// do something
}
For facts:
- Don't put a semi-colon at the end of the for condition
- Remember to create the variable used to count the loop with an int statement
somewhere in your program. (either in the for statement or before it)
- You can add to the counter between the brackets as well.
- After the first time through, the for loop does the "statement to run when
the loop repeats" first, and then checks whether the condition fails.
- When the condition fails, it goes to the bottom bracket of the loop and
continues on
- You can have loops inside loops
- Stopping when equal to a single number is dangerous - go with < or >
instead when you can.
- Variables you create inside a loop only last while the loop is running.
Loop approach: (No need to memorize. Just figure out which approach works best
for you)
- Write sample output
- bracket and label patterns on top of output
- determine outer and inner
- if inner, use a table to figure out
- work out example in the middle of a series
- flow chart
- pseudo code
- code outer and compile
- code one inner at a time and compile
Structure Summary: (You should know how to create each of these structures)
- Class header
- Final variable (public static final type name) CONSTANT
- Method header
- for heder
- statements
- delcare variables
- assign variable values
- expressions
Theory Summary:
- Naming
- cap first is class
- cap all is constant
- lower first is variable and method
- Types (int, char, boolean, double)
- Variables and expressions
- When to create
- What forumlas (start small # in middle of the sequence)
- How to evaluate expressions
- Flow chart
- Tracing programs
- Why to break into methods
- complexity
- reusable parts
- Repetition
- outer loop
- inner loop
- locate patterns
a