Loop Types && Syntax
For Loop
int studyTime = 0;
int sleepTime = 24;
for (int sleepTime = 24 ; sleepTime > 8 ; sleepTime--)
{
studyTime++;
sleepTime--;
}
The statement(s) are executed for a set amount of times, which is dependent
on the initialization, condition, and increment/decrement (update).
Condition
Increment/Decrement
Initialization
Statement(s)
Loop Types && Syntax
Do Loop
int studyTime = 0;
int sleepTime = 24;
do
{
sleepTime--;
studyTime++;
} while(sleepTime > 8);
The statement(s) are executed first, then the condition is checked after and
the statement(s) are executed again as long as the condition remains true. (In
other words, the statement(s) are always executed at least once.)
Statement(s)
Condition
Nested Loops
Think “For each relation”:
Example: Find all prime numbers between 0-100.
1. To check if a number is prime, we check if any number smaller than it is a factor
(x % i != 0 where i is all numbers smaller than x) <- This is the inner loop
2. We do this “for each” number between 0-100 <-This is the outer loop
..So what are Classes, Methods, and Objects?
Classes = Programmer defined (complex) data types. They are the blueprint for a
collection of objects that relate to the class in some shape/form.
Ex: Scanner and Decimalformat.
Objects = An instance of a class, they are a specific element from the collection (class)
Ex: