For Loops in Java: Inquiry Worksheet
[Link]
Part 1: Initial Observations and Questions
Watch and Wonder
After watching the video about for loops in Java, write down your initial observations and questions.
1. What did you notice about the structure of a for loop?
_Write 2-3 observations about how for loops are written in Java._
- There are three statements in the “()” of the for loops: the start value, the inequality, and the increments.
- A for loop seems similar to an if statement in the rest of the structure — the “{}” is present and they both
consist of a word then the parenthesis of information, and then the body.
-
2. Generate Questions
Write 3 questions you have about for loops after watching the video:
- Question 1: What happens if one statement is missing?
- Question 2: Could there be a different word for a for loop to start?
- Question 3: What is the difference between while loops and for loops?
Part 2: Investigating the Three Statements
Inquiry Challenge: Decode the Pattern
The video mentions that for loops have three statements separated by semicolons.
3. Based on your observations, what do you think each statement does?
Statement Purpose Example from Video
Position
First Statement Used for initialization int i = 0
Second Condition telling the i<10
Statement program when to
stop
Third Statement Step size i++
4. Hypothesis Formation
What do you predict would happen if you changed each of these statements? Make three predictions:
- If I change the first statement: The number of times the loop runs would be different depending on which
integer “i” is now.
- If I change the second statement: The number of times the loop runs would also change since the “upper
bound” would change.
- If I change the third statement: The step size of the loop would change resulting in a different number of times
the loop runs.
Part 3: Pattern Recognition Investigation
Analyzing the Output Sequences
The video showed several different for loop examples with different outputs.
5. Pattern Detective
For each scenario below, predict what the output would be and explain your reasoning:
Scenario A:
```java
for(int i = 0; i < 5; i++) {
[Link](i);
}
```
Predicted output:
0
1
2
3
4
Reasoning: The program starts with 0 and has increments of 1 and cannot be equal to 5 or exceed 5.
Scenario B:
```java
for(int i = 2; i <= 8; i += 2) {
[Link](i);
}
```
Predicted output:
2
4
6
8
Reasoning: The program starts with 2, has increments of 2, and cannot exceed 8.
Scenario C:
```java
for(int i = 15; i > 0; i -= 3) {
[Link](i);
}
```
Predicted output:
15
12
9
6
3
Reasoning: The program starts with 15, has decrements of 3, and cannot be less than or equal to 0.
Part 4: Real-World Application Inquiry
Connecting to Everyday Problems
6. Problem-Solving Investigation
Think about situations in your daily life where you repeat actions a specific number of times. List 3 examples
and explain how a for loop might model each situation:
- Example 1: Petting my dog 10 times.
How a for loop applies: Repeat the action of petting the dog 10 times in the loop.
- Example 2: Reading a book and flipping through the pages.
How a for loop applies: Repeat the action of flipping through the pages however many pages the book has
but it also must match my reading speed.
- Example 3: Spamming my friends
How a for loop applies: Make the text into a for loop and then I wouldn’t have to type it again and again.
7. Design Challenge
The video showed a countdown program. Design your own for loop application:
Your Program Idea: Spamming my friend 20 times with “HI”.
What would your three statements be?
- Initialization: int i = 0
- Condition: i<20
- Update: i++
What would the output look like?
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
HI
Part 5: Extension and Synthesis
Creative Application
Design a program that uses a for loop to solve a problem or create something interesting. Consider:
Problem/Goal: To make a window out of text for fun.
How many times should your loop run? Whatever length of the window the user would like.
What should happen during each iteration? There should be, “| | |” printed on a new line.
The middle should be like, “|---------------+ —-------------|”. The top and bottom (not in a loop) should be like,
“----------------------”
What should be the final result?
Something like
—-------------------------------------
| | |
| | |
| | |
| | |
|-------------------+-------------------|
| | |
| | |
| | |
| | |
—-------------------------------------
10. Reflection Questions
- What was the most surprising thing you learned about for loops? The step size of for loops could be changed
which is very convenient.
- What questions do you still have? How do for loops interact with break statements?
- How might for loops be useful in other programming projects? In programming projects, it could help reduce
the code by condensing several similar steps into one command.