1 / 8100%
Dr. Grover’s CSE 110
T / Th 3:00 - 4:15
CSE 110 E #2 Review
What main topics will be covered on this exam?
Loops
Classes and Objects
Methods
Loop Types && Syntax
While Loop
int studyTime = 0;
int sleepTime = 24;
while (sleep > 8)
{
studyTime++;
sleepTime--;
}
The statement(s) are executed if the condition is true, then
the statement(s) are executed again as long as the condition remains true.
Statement(s)
Condition
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:
A few examples for classes and objects
Class: Student -> Object: You
Class: University -> Object: ASU
Class: Company -> Object: Google
Powered by TCPDF (www.tcpdf.org)
Students also viewed