In today's class, we learned about for loops.
Iteration Statements:
Allows us to execute a statement multiple times
Often referred to as loops
Like conditional statements (if-else statements), they are controlled by boolean expressions
Java has 3 kinds of repetition statements
for loop
while loop
do loop
Programmers should choose the right kind for the situation
The for statement
for(initialization; condition; increment){
statement;
}
The initiation is executed once before the loop begins
The statement is executed until the condition becomes false
The increment portion is executed at the end of each iteration
Best for executing statements a specific number of times that can be determined in advance
Example:
for(int count = 1; count <= 5; count++){
System.out.println(count);
}
Solution: https://replit.com/@liizz/128-HW-Solution#Main.java