Lesson Plan
Course Title: Computer Programming
Session Title: For Loops
Lesson Duration: 3-4 hours
Performance Objective: Upon completion of this assignment, the student will recognize and
explain the parts of a “for loop” and be able to create and modify for loops to perform specified
tasks.
Specific Objectives:
Design for loops based on specification
Produce a procedural program that incorporates for loops
Compare the output of a for loop with expected results and modify it if needed
Preparation
TEKS Correlations: 130.276(c)
6.B – perform a logical design
7.C – produce procedural coding
7.E – compare computed results with anticipated results
Instructor/Trainer
References:
• Content Developer Knowledge
• Java Software Solutions for AP Computer Science, by Lewis, Loftus, & Cocking, copyright
2004, Pearson Education, Inc .
• Introduction to Computer Science using Java, by Liberty, Quirk & Weiss, copyright 2005,
Glencoe McGraw-Hill
Instructional Aids:
• Presentation: ‘Intro to For Loops’
• Handout & KEY: ‘Guided Notes: Intro to For Loops’
• Handout & Lab File & KEY: ‘Observing For Loops’ & ‘ObservingFor.java’
• Lab File: ‘ForPractice.java’
• Lab File: ‘UsingFor.java’
• Handout & KEY: ‘For Loop Review’
• Handout & KEY: ‘For Loop Quiz A, B, & C’
• Handout & Lab File: MayanLongCount & MayanLongCount.java
Materials Needed:
• Copies of Instructional aides
• Pencil or pen
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
1
Equipment Needed: Each student will need access to a computer with Java installed and
access to the internet for research.
Learner
The learner should have understanding of simple Java code, including system output and data
types.
Introduction
MI
Introduction (LSI Quadrant I):
Begin the presentation with a group discussion about repetitive activities, such as
counting, dealing cards, or serving lunch in a cafeteria line. Help the group to
understand that these activities involve the same task repeated a certain number of
times. Have the group list examples of this kind of activity. Discuss what the
advantages might be if you could simply define a job, and then have it repeated a
certain number of times.
This should prepare the group for the Presentation.
Discussion should take 5 minutes.
Outline
MI
Outline (LSI Quadrant II):
Instructor Notes:
The instructor presents the ‘Intro to For Loops’
Presentation. Students follow along using the ‘Intro
to For Loops Guided Notes.’ The instructor can
pause at any point to expand the discussion or
clarify concepts.
The Presentation and guided
notes can also be used by
students who were absent
and trying to catch up. It can
also be used as a review.
Terms & Concepts presented:
• The basic parts of for loop syntax, including the
initialization, condition, and step statements.
• Counter variables declared outside of the for
loop persist after the loop. Variables declared
inside of the loop do not exist outside of the loop.
• Curly brackets create a block statement, but for
loops without brackets only contain one
statement.
• Special syntax in the step statement allows the
loop to move forward or backward or by various
increments.
The guided notes may be
graded using the KEY to
check student understanding.
Students who do not
complete the guided notes
during the presentation may
need to review the
Presentation on their own
time.
The Presentation, discussion, and notes should take
15 – 20 minutes.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
2
Application
MI
Guided Practice (LSI Quadrant III):
Handout & Lab File: ‘Observing For Loops’
The teacher can begin this lab by showing it to the students on the overhead
projector and discussing different parts of the code. The teacher might even guide
the class through the first few questions to get them started. Students should then be
able to complete the lab individually or in pairs.
The students’ goal is to observe, analyze, and report what happens as they follow
the various instructions that are in the lab. The student uses numbered questions in
the handout that correspond to numbered segments in the lab file that have
instructions. The student follows the numbered instructions in the code and answers
questions about the code and about the output when the lab file is run.
There are output statements in each numbered section of the code that allow the
student to predict the range of numbers that will be printed in that section. The
student should look at the code ahead of time, and type their prediction in each
output statement BEFORE compiling and running the code.
This lab reinforces for loop terminology and concepts, including initialization,
condition and step statements. Encourage students to look at the entire lab file
before running the lab or answering questions. One of the benefits of this lab is that
the student learns to predict the outcome of a for loop, using the concepts given in
the Presentation.
This lab can be completed in 15-20 minutes. There is a KEY to assess student
understanding.
MI
Independent Practice (LSI Quadrant III):
Lab File: ‘ForPractice.java’
In this lab exercise, students follow numbered instructions that are imbedded in the
code. Instruction #0 is already completed in the code as an example for the
students. Students may refer to the ‘observation’ lab for code examples. The
teacher assesses the lab by looking at the code and having the student run the
completed lab to check the output statements.
ForPractice.java helps the student to gain confidence in reading and making minor
code modifications. This lab takes 10-15 minutes.
Summary
MI
Review (LSI Quadrants I and IV):
Handout & KEY: ‘For Loop Review’
Students can use their notes and the Presentation to answer questions about class
terms, concepts, and code segments. The teacher may allow students to grade their
own self-evaluation, but should hold them accountable for correcting any errors by
writing explanations for any question that they miss.
The evaluation helps students assess their own understanding of the material and
readiness for the quiz. This self-evaluation takes 10-15 minutes.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
3
Evaluation
MI
Informal Assessment (LSI Quadrant III):
Lab File: ‘UsingFor.java’
In this lab there are 9 numbered instructions imbedded in the code. Students
complete the lab by writing a few lines of code to follow each instruction. The teacher
evaluates the lab by looking at the student’s code additions in each section and by
observing the output. Students can use examples from previous labs to complete the
instructions. There is a KEY for this lab, ‘UsingForKEY.java’. This lab takes 20-30
minutes.
MI
Formal Assessment (LSI Quadrant III, IV):
Handouts & KEYs: ‘For Loop Quiz A, B, & C’
These Quizzes are used as formal assessment of students’ understanding of for
loop terminology and concepts. Each one contains similar material that is
rearranged. The ‘C’ version is modified with fewer questions. The quiz takes 10-15
minutes to complete.
Extension
MI
Extension/Enrichment (LSI Quadrant IV):
Handout and Lab and KEYs : ‘Mayan Long Count and MayanLongCount.java’
This exercise challenges students to apply their understanding of for loops by
recreating the Mayan long count calendar, which consists of 5 digits, representing
the Mayan day, month, year, decade, and century. The long count starts at 0.0.0.0.0
which represents 14 Aug 3114 BC, and ends at 13.0.0.0.0 which is 21Dec 2012.
Students begin by researching the long count calendar online. Students will answer
simple questions on the handout to ensure that they understand the range of each of
the five sets of numbers.
Students apply their knowledge by modifying the MayanLongCount.java lab file so
that it uses nested for loops to print from 0.0.0.0.0 to 13.0.0.0.0.
Student instructions are in the file. Labs are assessed by looking at the code and the
output. There is a KEY for both the handout and the lab. Encourage the students to
have fun with the lab and to show each other their output. Printing the entire
calendar takes a while, which adds to the anticipation of getting the final date
correct.
For troubleshooting purposes, students can set the Baktun limit to 1 instead of 13, so
that the dates run from 0.0.0.0.0 to 1.0.0.0.0. When students are satisfied they have
the code correct, have them change the Baktun limit back to 13 to demonstrate their
code.
This lab takes from 20 – 40 minutes depending on student enthusiasm.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
4
Icon
MI
Verbal/
Linguistic
Logical/
Mathematical
Visual/Spatial
Musical/
Rhythmic
Bodily/
Kinesthetic
Intrapersonal
Interpersonal
Naturalist
Existentialist
Teaching Strategies
Personal Development
Strategies
Lecture, discussion, journal
writing, cooperative learning,
word origins
Reading, highlighting, outlining,
teaching others, reciting information
Problem solving, number
games, critical thinking,
classifying and organizing,
Socratic questioning
Mind-mapping, reflective
time, graphic organizers,
color-coding systems,
drawings, designs, video,
DVD, charts, maps
Use music, compose songs
or raps, use musical
language or metaphors
Organizing material logically, explaining
things sequentially, finding patterns,
developing systems, outlining, charting,
graphing, analyzing information
Developing graphic organizers, mindmapping, charting, graphing, organizing
with color, mental imagery (drawing in
the mind’s eye)
Use manipulatives, hand
signals, pantomime, real life
situations, puzzles and board
games, activities, roleplaying, action problems
Reflective teaching,
interviews, reflective listening,
KWL charts
Cooperative learning, roleplaying, group brainstorming,
cross-cultural interactions
Natural objects as
manipulatives and as
background for learning
Socratic questions, real life
situations, global
problems/questions
Creating rhythms out of words, creating
rhythms with instruments, playing an
instrument, putting words to existing
songs
Moving while learning, pacing while
reciting, acting out scripts of material,
designing games, moving fingers under
words while reading
Reflecting on personal meaning of
information, studying in quiet settings,
imagining experiments, visualizing
information, journaling
Studying in a group, discussing
information, using flash cards with
other, teaching others
Connecting with nature, forming study
groups with like minded people
Considering personal relationship to
larger context
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
5
Name: _____________________ Date: ___________ Period: ____________
Intro to For Loops Guided Notes
Objective: Learn loop terminology and concepts
Instructions: Fill in the notes as you follow the presentation.
Intro to For Loops
1. Looping basically means to…
a. Increase the speed of calculations
b. Repeat an operation several times
2. To create a for loop, you must know the number of [ criterion / iterations / initializations ]
it needs to execute.
3. The keyword that identifies the for loop is [ for / loop / int ].
for ( int x = 0; x < 12 ; x ++)
4. In the for loop above, which is the condition? [ int x = 0
/ x < 12 / x ++ ]
5. In the for loop above, which is the initialization? [ int x = 0 / x < 12 / x ++ ]
6. In the for loop above, which is the step expression?
[ int x = 0
/ x < 12 / x ++ ]
7. For loops must be initialized to zero. [ T / F ]
8. The control expression is the same as the condition. [ T / F ]
9. To keep the for loop running, the condition must evaluate to [ True / False ].
10. The step expression must move the condition toward [ True / False ].
11. The step expression must always count up. [ T / F ]
Special Step Expression Syntax & Curly Brackets
12. The expression ‘k++’ means the same thing as ‘k = k + k’. [ T / F ]
13. The expression ‘x*=3’ means the same thing as ‘x = x*3’. [ T / F ]
14. Without curly brackets, how many lines are in the body of the for loop? [ 0 / 1 / 2 ]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
6
Initialization Variables
15. If the variable is declared inside the loop, it can also be used outside of the loop. [ T / F
]
16. A variable that is declared before the beginning of the for loop [ can / can NOT ] be
used after the end of the for loop.
17. If the loop count variable ‘k’ is declared outside of the loop, then after the loop the value
of k is…
a. The first value of k before the loop started.
b. The last value of k before the loop condition failed.
c. The value of k after the loop condition failed.
Review
18. Write a loop below that uses the count variable ‘x’ that is initialized to 0 and counts by
1’s up to 13.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
7
Name: _____________________ Date: ___________ Period: ____________
Intro to For Loops Guided Notes KEY
Objective: Learn loop terminology and concepts
Instructions: Fill in the notes as you follow the presentation.
Intro to For Loops
1. Looping basically means to…
a. To increase the speed of calculations
b. Repeat an operation several times
2. To create a for loop, you must know the number of [criterion / iterations / initializations ]
it needs to execute.
3. The keyword that identifies the for loop is [ for / loop / int ].
for ( int x = 0; x < 12 ; x ++)
4. In the for loop above, which is the condition? [ int x = 0
/ x < 12 / x ++ ]
5. In the for loop above, which is the initialization? [ int x = 0 / x < 12 / x ++ ]
6. In the for loop above, which is the step expression?
[ int x = 0
/ x < 12 / x ++ ]
7. For loops must be initialized to zero. [ T / F ]
8. The control expression is the same as the condition. [ T / F ]
9. To keep the for loop running, the condition must evaluate to [ True / False ].
10. The step expression must move the condition toward [ True / False ].
11. The step expression must always count up. [ T / F ]
Special Step Expression Syntax & Curly Brackets
12. The expression ‘k++’ means the same thing as ‘k = k + k’. [ T / F ]
13. The expression ‘x*=3’ means the same thing as ‘x = x*3’. [ T / F ]
14. Without curly brackets, how many lines are in the body of the for loop? [ 0 / 1 / 2 ]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
8
Initialization Variables
15. If the variable is declared inside the loop, it can also be used outside of the loop. [ T / F
]
16. A variable that is declared before the beginning of the for loop [ can / can NOT ] be
used after the end of the for loop.
17. If the loop count variable ‘k’ is declared outside of the loop, then after the loop the value
of k is…
a. The first value of k before the loop started.
b. The last value of k before the loop condition failed.
c. The value of k after the loop condition failed.
Review
18. Write a loop below that uses the count variable ‘x’ that is initialized to 0 and counts by
1’s up to 13. for (int x = 0; x <=13; x++)
or for (int x = 0; x < 14; x++)
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
9
Name: _____________________ Date: ___________ Period: ____________
Observing For Loops
Objective: Students analyze the code in ObservingFor.java.
Instructions: First complete the lab ObservingFor.java; fill out this form as you observe the
code and its execution. You may make changes to the code to test any of your answers.
1. In #1, the part of code that tells the counting where to start is [int i = 0
i++ ].
/
i<9
2. In #2, the part of code that tells the counting where to stop is [int i = 0
i++ ].
/
i <= 9
/
/
3. Using #1 and #2 as examples, which of the following would count from 0 to 12?
a. for (int i = 1; i <= 12; i++)
b. for (int i = 0; i < 12; i++)
c. for (int i = 0; i <= 12; i++)
4. In #3, the part of code that makes it count backward is [ int i = 0 / i <= 9 /
i-- ].
5. Using #3 as an example, which of the following would count from 12 to 1?
a. for (int i = 12; i >= 0; i--)
b. for (int i = 12; i > 0; i--)
c. for (int i = 13; i >= 0; i--)
6. Using #4 as an example, what would the following code produce?
for (int i = 3; i >= -1; i--)
System.out.print(i + " ");
a. 3 2 1 0 -1
b. 3 2 1 0
c. -1 0 1 2 3
7. In #5, which part of the code causes it to count by 3’s? [ int i = 3 / i <= 3 / i+=3 ]
8. Using #5 as an example, which of the following would count from 0 to 12 by 2’s? [for
(int i = 0; i <= 12; i+=2) / for (int i = 2; i <= 12; i+=0) ]
9. In #6, which part of the code causes it to count by 6’s? [ int i = 24 / i >= -6 /
i-=6 ]
10. #7 shows that you [ can / can not ] use variables in a for loop.
11. The difference between #8 and #9 is…
a. #8 has 2 statements in a block, but #9 does not.
b. #9 has 2 statements in a block, but #8 does not.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
10
12. In #10, the variable ‘x’ is declared [inside / outside ] of the for loop.
13. In #10, the last value of x inside the loop is ___.
14. In #10, the last value of x after the loop is ___.
15. In #10, after the loop runs, the value of x outside of the loop is greater than the last value
of x inside the loop because…
a. It was incremented after the loop was over.
b. It was incremented inside the loop; then failed the loop condition.
c. It failed the loop condition; then was incremented inside the loop.
16. In #11, the first time ‘y’ is printed inside the loop, the value is ____.
17. In #11, when ‘y’ is printed after the loop, the value is ____.
18. In # 11, what happens first?
a. The value of ‘y’ gets incremented.
b. The body of the loop runs.
19. In #12, the print statement inside the loop [ does / does NOT ] execute.
20. In #12, what is wrong with the for loop?
a. The value of ‘z’ is not less than 4, so the for loop fails immediately.
b. The value of ‘z’ is changed to 4, then 3 is added to it.
c. The value of ‘z’ starts at 8, then gets incremented to 11.
21. If you un-comment all the lines in #13, then compile and run it, what happens?
a. The loop never runs.
b. The loop never stops running.
c. The loop runs until it reaches the limit of the condition.
22. If you un-comment all the lines in #13, why does it run the way it does?
a. The loop condition fails before the loop runs.
b. The loop condition never fails.
c. The loop condition eventually fails when the value of ‘a’ is incremented high
enough.
Conclusions
23. If you want to use a variable during the for loop, and after the for loop is finished, you
should declare that variable…
a. Inside the for loop
b. After the for loop
c. Before the for loop
24. The for loop statement for(int k = 7; k< 14; k+=3) means…
a. With k starting at 7, add 3 to k until k reaches 14
b. With k starting at 7, add 3 to k until k is greater than 14
c. With k starting at 7, add 3 to k as long as k is less than 14
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
11
Name: _____________________ Date: ___________ Period: ____________
Observing For Loops KEY
Objective: Students analyze the code in ObservingFor.java.
Instructions: First complete the lab: ObservingFor.java; fill out this form, as you observe the
code and its execution. You may make changes to the code to test any of your answers.
1. In #1, the part of code that tells the counting where to start is [int i = 0
i++ ].
/
i<9
/
2. In #2, the part of code that tells the counting where to stop is [int i = 0
i++ ].
/ i <= 9
/
3. Using #1 and #2 as examples, which of the following would count from 0 to 12?
a. for (int i = 1; i <= 12; i++)
b. for (int i = 0; i < 12; i++)
c. for (int i = 0; i <= 12; i++)
4. In #3, the part of code that makes it count backward is [ int i = 0 / i <= 9 /
i-- ].
5. Using #3 as an example, which of the following would count from 12 to 1?
a. for (int i = 12; i >= 0; i--)
b. for (int i = 12; i > 0; i--)
c. for (int i = 13; i >= 0; i--)
6. Using #4 as an example, what would the following code produce?
for (int i = 3; i >= -1; i--)
System.out.print(i + " ");
a. 3 2 1 0 -1
b. 3 2 1 0
c. -1 0 1 2 3
7. In #5, which part of the code causes it to count by 3’s? [ int i = 3 / i <= 3 / i+=3 ]
8. Using #5 as an example, which of the following would count from 0 to 12 by 2’s? [for
(int i = 0; i <= 12; i+=2) / for (int i = 2; i <= 12; i+=0) ]
9. In #6, which part of the code causes it to count by 6’s? [ int i = 24 / i >= -6
/ i-=6 ]
10. #7 shows that you [ can / can not ] use variables in a for loop.
11. The difference between #8 and #9 is…
a. #8 has 2 statements in a block, but #9 does not.
b. #9 has 2 statements in a block, but #8 does not.
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
12
12. In #10, the variable ‘x’ is declared [inside / outside ] of the for loop.
13. In #10, the last value of x inside the loop is _3__.
14. In #10, the last value of x after the loop is _4__.
15. In #10, after the loop runs, the value of x outside of the loop is greater than the last value
of x inside the loop because…
a. It was incremented after the loop was over.
b. It was incremented inside the loop, then failed the loop condition.
c. It failed the loop condition, then was incremented inside the loop.
16. In #11, the first time ‘y’ is printed inside the loop, the value is __8__.
17. In #11, when ‘y’ is printed after the loop, the value is __9__
.
18. In # 11, what happens first?
a. The value of ‘y’ gets incremented.
b. The body of the loop runs.
19. In #12, the print statement inside the loop [ does / does NOT ] execute.
20. In #12, what is wrong with the for loop?
a. The value of ‘z’ is not less than 4, so the for loop fails immediately.
b. The value of ‘z’ is changed to 4, then 3 is added to it.
c. The value of ‘z’ starts at 8, then gets incremented to 11.
21. If you un-comment all the lines in #13, then compile and run it, what happens?
a. The loop never runs.
b. The loop never stops running.
c. The loop runs until it reaches the limit of the condition.
22. If you un-comment all the lines in #13, why does it run the way it does?
a. The loop condition fails before the loop runs.
b. The loop condition never fails.
c. The loop condition eventually fails when the value of ‘a’ is incremented high
enough.
Conclusions
23. If you want to use a variable during the for loop, and after the for loop is finished, you
should declare that variable…
a. Inside the for loop
b. After the for loop
c. Before the for loop
24. The for loop statement for(int k = 7; k< 14; k+=3) means…
a. With k starting at 7, add 3 to k until k reaches 14
b. With k starting at 7, add 3 to k until k is greater than 14
c. With k starting at 7, add 3 to k as long as k is less than 14
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
13
Name: _____________________ Date: ___________ Period: ____________
Review: For Loop
Objective: Students identify and practice recently learned for loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. for (int j = 5; j < 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
2. for (int j = 5; j > 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
3. for (int j = 5; j <= 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
4. for (int j = 5; j <= 5; j--) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
5. for (int j = 1; j < 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
6. for (int j = 1; j <= 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
7. for (int j = 1; j > 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
14
8. for (int j = 1; j < 10; j*=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
9. for (int j = start; j < stop; j += step) Fill in each of the variable values so that the value
of j will be 0, 2, 4, 6 when the loop runs.
• start = _____
• stop = _____
• step = _____
10. for (int j = start; j < stop; j += step) Fill in each of the variable values so that the value
of j will be 6, 3, 0 when the loop runs.
• start = ____
• stop = ____
• step = ____
11. Complete the for loop so that the value of j will be 27, 9, 3
for ( int j = 27 ; j>=3; j ______)
.
int k = 0;
for (k = 3; k < 6; k++) {
System.out.println(“hello”);
}
System.out.println(k)
12. Look at the code above. What will be the value of k when the for loop is over and the
print statement prints the value of k?
a. 0
b. 3
c. 5
d. 6
e. none of these
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
15
Name: _____________________ Date: ___________ Period: ____________
Review: For Loop KEY
Objective: Students identify and practice recently learned for loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. for (int j = 5; j < 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
2. for (int j = 5; j > 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
3. for (int j = 5; j <= 5; j++) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
4. for (int j = 5; j <= 5; j--) How many times would this loop run?
a. Infinite number
b. 1
c. Not at all
5. for (int j = 1; j < 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
6. for (int j = 1; j <= 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
7. for (int j = 1; j > 10; j+=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
16
c. 1, 4, 7, 10
d. None of these
8. for (int j = 1; j < 10; j*=3) What would the value of ‘j’ be as this loop runs?
a. 1, 4, 7
b. 1, 3, 9
c. 1, 4, 7, 10
d. None of these
9. for (int j = start; j < stop; j += step) Fill in each of the variable values so that
the value of j will be 0, 2, 4, 6 when the loop runs.
• start = __0__
• stop = __7 or 8__
• step = __2__
10. for (int j = start; j < stop; j += step) Fill in each of the variable values so that
the value of j will be 6, 3, 0 when the loop runs.
• start = __6__
• stop = __-1, or -2, or -3__
• step = __-3__
11. Complete the for loop so that the value of j will be 27, 9, 3
.
for ( int j = 27 ; j>=3; j /= 3)
int k = 0;
for (k = 3; k < 6; k++) {
System.out.println(“hello”);
}
System.out.println(k)
12. Look at the code above. What will be the value of k when the for loop is over and
the print statement prints the value of k?
a. 0
b. 3
c. 5
d. 6
e. none of these
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
17
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz A
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “1 4 7 10 13” ?
a) for (int i = 1; i <= 14; i+=3)
b) for (int i = 0; i <= 14; i+=3)
c) for (int i = 1; i <= 14; i*=3)
2. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “27 9 3 1” ?
a) for (int i = 27; i > 0; i-=3)
b) for (int i = 27; i > 0; i/=3)
c) for (int i = 27; i < 0; i/=3)
3. What would the following code print? for (int i = 2; i <19; i*=2) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16 18
b) 2 4 8 16
c) 2 4 16
4. In the for loop for (int x = 12; x < 12; x+=3), the condition is [x+=3 / x < 12
12 /
]
/
int x =
5. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
6. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
7. What would the following code print? for (int i = 1; i <7; i+=2) System.out.print(i + " ");
System.out.print(“hi");
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
8. Using the counter k, and the variables START, STOP, and INCR, write a for loop that
counts up from START to STOP, by multiples of INCR. Do not bother writing the print
statement. _______________________________________
9. Write a for loop and use 2 print statements, and prints every grade of high school, (9
10 11 12) and the word “grade” after each grade level.
for (_____________________________)
________________________________;
_________________________________;
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
18
Use the following code to answer the questions below
// #A
int a = 0;
for (a = 1;a > 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
int b = 0;
for (b = 2;b <= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
//for (int c = 3;c > -6; c +=3)
//System.out.print(" " + c);
// #D
for (int d = 16;d >= 2; d /=2)
System.out.print(" " + d);
// #E
System.out.println("\n#E");
for (int e = 2;e <=30; e *=e)
System.out.print(" " + e);
10. What will code segment #A print?
[
1
/
1 4 7
11. What will code segment #B print?
[ 2
/
2 5
/
2 5 8
12. What will code segment #C print?
[
3 0 -3
/
3
/
/
nothing
/
nothing
nothing
/
13. What will code segment #D print?
[ 16 8 4 2
/ 16 4 2
/
nothing
14. What will code segment #E print?
[
2 4 8 16
/
2 4 16 /
nothing
/ infinite loop
/
/
/
infinite loop ]
infinite loop
]
infinite loop
]
infinite loop
]
]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
19
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz A KEY
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “1 4 7 10 13” ?
a) for (int i = 1; i <= 14; i+=3)
b) for (int i = 0; i <= 14; i+=3)
c) for (int i = 1; i <= 14; i*=3)
2. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “27 9 3 1” ?
a) for (int i = 27; i > 0; i-=3)
b) for (int i = 27; i > 0; i/=3)
c) for (int i = 27; i < 0; i/=3)
3. What would the following code print? for (int i = 2; i <19; i*=2) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16 18
b) 2 4 8 16
c) 2 4 16
4. In the for loop for (int x = 12; x < 12; x+=3), the condition is [x+=3 / x < 12
12 /
]
/
int x =
5. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
6. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
7. What would the following code print? for (int i = 1; i <7; i+=2) System.out.print(i + " ");
System.out.print(“hi");
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
8. Using the counter k, and the variables START, STOP, and INCR, write a for loop that
counts up from START to STOP, by multiples of INCR. Do not bother writing the print
statement. for ( int k = START ; k <= STOP ; k * = INCR )
9. Write a for loop and use 2 print statements, and prints every grade of high school, (9
10 11 12) and the word “grade” after each grade level.
for (int k = 9 ; k <= 12; k++) {
System.out.print(k);
System.out.println(“grade”);
}
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
20
Use the following code to answer the questions below
// #A
int a = 0;
for (a = 1;a > 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
int b = 0;
for (b = 2;b <= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
//for (int c = 3;c > -6; c +=3)
//System.out.print(" " + c);
// #D
for (int d = 16;d >= 2; d /=2)
System.out.print(" " + d);
// #E
System.out.println("\n#E");
for (int e = 2;e <=30; e *=e)
System.out.print(" " + e);
10. What will code segment #A print?
[
1
/
1 4 7
11. What will code segment #B print?
[ 2
/
2 5
/
2 5 8
12. What will code segment #C print?
[
3 0 -3
/
3
/
/
nothing
/
nothing
nothing
/
13. What will code segment #D print?
[ 16 8 4 2
/ 16 4 2
/
nothing
14. What will code segment #E print?
[
2 4 8 16
/
2 4 16 /
nothing
/ infinite loop
/
/
/
infinite loop ]
infinite loop
]
infinite loop
]
infinite loop
]
]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
21
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz B
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “2 5 8 11 14” ?
a) for (int i = 2; i <= 17; i+=3)
b) for (int i = 2; i <= 14; i*=3)
c) for (int i = 2; i <17; i+=3)
2. In the for loop for (int x = 12; x < 12; x+=3), the condition is [ x < 12
12 /
].
/ x+=3 / int x =
3. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “27 9 3 1” ?
a) for (int i = 27; i > 0; i/=3)
b) for (int i = 27; i > 0; i-=3)
c) for (int i = 27; i < 0; i/=3)
4. What would the following code print? for (int i = 2; i <=16; i*=i) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16
b) 2 4 8 16
c) 2 4 16
5. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
6. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
7. What would the following code print? for (int i = 1; i <7; i+=2){ System.out.print(i + "
"); System.out.print(“hi");}
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
8. Using the counter k, and the variables BEGIN, END, and STEP, write a for loop that
counts up from BEGIN to END, by multiples of STEP. Do not bother writing the print
statement. ________________________________________
9.
Write a for loop and use 2 print statements, and prints every grade of high school, (9
10 11 12) and the word “grade” after each grade level.
for ( _____________________________){
__________________________________;
__________________________________;
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
22
Use the following code to answer the questions below
// #A
int a = 0;
for (a = 1;a < 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
int b = 0;
for (b = 2;b >= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
for (int c = 3;c < -6; c +=3)
System.out.print(" " + c);
// #D
for (int d = 32;d >= 4; d /=2)
System.out.print(" " + d);
// #E
for (int e = 20;e >=3; e +=e)
System.out.print(" " + e);
10. What will code segment #A print?
[ 1 /
1 4 7
/
1 4 7 10
/
11. What will code segment #B print?
[ 2
/
2 5
/
2 5 8
12. What will code segment #C print?
[
3 0 -3
/
3
/
/
nothing
nothing
/ infinite loop
nothing
/
/
infinite loop ]
infinite loop
13. What will code segment #D print?
[ 32 / 32 16 4 /
32 16 8 4
/
nothing
/
14. What will code segment #E print?
[ 20
/ 20 10 5
/
nothing
/
infinite loop
]
]
]
infinite loop
]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
23
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz B KEY
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “2 5 8 11 14” ?
a) for (int i = 2; i <= 17; i+=3)
b) for (int i = 2; i <= 14; i*=3)
c) for (int i = 2; i <17; i+=3)
2. In the for loop for (int x = 12; x < 12; x+=3), the condition is [ x < 12
12 /
].
/ x+=3 / int x =
3. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “27 9 3 1” ?
a) for (int i = 27; i > 0; i/=3)
b) for (int i = 27; i > 0; i-=3)
c) for (int i = 27; i < 0; i/=3)
4. What would the following code print? for (int i = 2; i <=16; i*=i) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16
b) 2 4 8 16
c) 2 4 16
5. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
6. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
7. What would the following code print? for (int i = 1; i <7; i+=2){ System.out.print(i + "
"); System.out.print(“hi");}
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
8. Using the counter k, and the variables BEGIN, END, and STEP, write a for loop that
counts up from BEGIN to END, by multiples of STEP. Do not bother writing the print
statement. for (int k = BEGIN; k <= END; k+=STEP)
9.
Write a for loop and use 2 print statements, and prints every grade of high school,(9
10 11 12) and the word “grade” after each grade level.
for ( int k = 9; k <= 12; k ++){
System.out.print(k);
System.out.println(“grade”);
}
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
24
Use the following code to answer the questions below
// #A
int a = 0;
for (a = 1;a < 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
int b = 0;
for (b = 2;b >= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
for (int c = 3;c < -6; c +=3)
System.out.print(" " + c);
// #D
for (int d = 32;d >= 4; d /=2)
System.out.print(" " + d);
// #E
for (int e = 20;e >=3; e +=e)
System.out.print(" " + e);
10. What will code segment #A print?
[ 1 /
1 4 7
/
1 4 7 10
/
11. What will code segment #B print?
[ 2
/
2 5
/
2 5 8
12. What will code segment #C print?
[
3 0 -3
/
3
/
/
nothing
nothing
/ infinite loop
nothing
/
/
infinite loop ]
infinite loop
13. What will code segment #D print?
[ 32 / 32 16 4 /
32 16 8 4
/
nothing
/
14. What will code segment #E print?
[ 20
/ 20 10 5
/
nothing
/
infinite loop
]
]
]
infinite loop
]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
25
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz C
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “1 4 7 10 13” ?
a) for (int i = 0; i <= 14; i+=3)
b) for (int i = 1; i <= 14; i*=3)
c) for (int i = 1; i <= 14; i+=3)
2. What would the following code print? for (int i = 2; i <19; i*=2) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16 18
b) 2 4 8 16
c) 2 4 16
3. Using the counter k, and the variables START, STOP, and INCR, write a for loop that
counts up from START to STOP, by multiples of INCR. Do not bother writing the print
statement. for (____________________________________)
4. In the for loop for (int x = 12; x < 12; x+=3), the condition is [x+=3 / x < 12
12 /
].
/
int x =
5. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
6. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
7. What would the following code print? for (int i = 1; i <7; i+=2) System.out.print(i + " ");
System.out.print(“hi");
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
Use the following code to answer the questions below.
// #A
int a = 0;
for (a = 1;a > 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
8. What will code segment #A print?
[
1
/
1 4 7
/
nothing
/ infinite loop
]
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
26
// #E
System.out.println("\n#E");
for (int e = 2;e <=30; e *=e)
System.out.print(" " + e);
9. What will code segment #E print?
[
2 4 8 16
/
2 4 16 /
nothing
/
infinite loop
]
// #B
int b = 0;
for (b = 2;b <= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
10. What will code segment #B print?
[
2 5
/
2 5 8
/
nothing
/
infinite loop ]
// #C
//for (int c = 3;c > -6; c +=3)
//System.out.print(" " + c);
11. What will code segment #C print?
[
3 0 -3
/
3
/
nothing
/
infinite loop
]
infinite loop
]
// #D
for (int d = 16;d >= 2; d /=2)
System.out.print(" " + d);
12. What will code segment #D print?
[ 16 8 4 2
/ 16 4 2
/
nothing
/
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
27
Name: _____________________ Date: ___________ Period: ____________
For Loop Quiz C KEY
Objective: Students demonstrate mastery of loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. Assuming it contains the print statement System.out.print(i + “ “); which of the
following loops prints “1 4 7 10 13” ?
a) for (int i = 0; i <= 14; i+=3)
b) for (int i = 1; i <= 14; i*=3)
c) for (int i = 1; i <= 14; i+=3)
2. What would the following code print? for (int i = 2; i <19; i*=2) System.out.print(i + "
");
a) 2 4 6 8 10 12 14 16 18
b) 2 4 8 16
c) 2 4 16
3. Using the counter k, and the variables START, STOP, and INCR, write a for loop that
counts up from START to STOP, by multiples of INCR. Do not bother writing the print
statement. for ( int k = START ; k <= STOP ; k * = INCR )
4. In the for loop for (int x = 12; x < 12; x+=3), the condition is [x+=3 / x < 12
12 /
].
/
int x =
5. The for loop for (int x = -2; x < 2; x--), will execute [ 0 / 1 / 3 / 4 / infinity ] times.
6. The for loop for (int x = 12; x > 15; x++), will execute [ 0 / 1 / 3 / 4 / infinity] times.
7. What would the following code print? for (int i = 1; i <7; i+=2) System.out.print(i + " ");
System.out.print(“hi");
a) 1 hi 3 hi 5 hi
b) 1 hi 3 hi 5 hi 7 hi
c) 1 3 5 hi
Use the following code to answer the questions below
// #A
int a = 0;
for (a = 1;a > 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
28
8. What will code segment #A print?
[
1
/
1 4 7
/
nothing
/ infinite loop
]
// #E
System.out.println("\n#E");
for (int e = 2;e <=30; e *=e)
System.out.print(" " + e);
9. What will code segment #E print?
[
2 4 8 16
/
2 4 16 /
nothing
/
infinite loop
]
// #B
int b = 0;
for (b = 2;b <= 7; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
10. What will code segment #B print?
[
2 5
/
2 5 8
/
nothing
/
infinite loop ]
// #C
//for (int c = 3;c > -6; c +=3)
//System.out.print(" " + c);
11. What will code segment #C print?
[
3 0 -3
/
3
/
nothing
/
infinite loop
]
infinite loop
]
// #D
for (int d = 16;d >= 2; d /=2)
System.out.print(" " + d);
12. What will code segment #D print?
[ 16 8 4 2
/ 16 4 2
/
nothing
/
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
29
Name: _____________________ Date: ___________ Period: ____________
Mayan Long Count
Objective: Apply nested for loops to recreate the Mayan Long Count calendar.
Instructions: Do an internet search (keyword: Mayan Long Count) to answer the questions
below; then follow the steps to create code to display all the dates in the Mayan Long Count
calendar. Note: The word ‘Winal’ may also be spelled ‘Uinal.’
Investigation
1. The word for one day is: Baktun / Katun / Kin /
Tun / Winal
2. The word for 20 days is: Baktun / Katun / Kin / Tun / Winal
3. The word for 18 Winals is: Baktun / Katun / Kin / Tun / Winal
4. The word for 20 Tuns is: Baktun / Katun / Kin / Tun / Winal
5. The word for 20 Katuns is: Baktun / Katun / Kin / Tun / Winal
6. How many days would be in one Tun? 1 / 20 / 360 / 7200
7. Write these in order from least to greatest (Baktun / Katun / Kin / Tun / Winal )
a. ____________
b. ____________
c. ____________
d. ____________
e. ____________
8. How many days are there in one year according to our calendar?
30 / 200 / 365 / 410 / 500
9. According to our clock, there are 24 hours in a full day. One second less than a full day
would be _____ hours, _____ minutes, and _____ seconds.
10. If the Long Count date for 14 Aug 3114 BC is 0.0.0.0.0, what is the date for 16 Aug 3114
BC? _________________
11. If the Long Count date for 14 Aug 3114 BC is 0.0.0.0.0, what is the date 20 days later?
__________________
12. If the Long Count date for 21 Dec 2012 is 13.0.0.0.0, what is the date for 20 Dec 2012?
__________________
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
30
Coding Instructions: Modify the file LongCount.java to do the following:
13. Set the variable Kin to the correct integer value to control a for loop that counts from 0 to
19.
14. Create a for loop that prints each Kin in a Winal. ( ex: 0, 1, 2, … 19)
15. Set the variable Winal to the correct integer value to control a for loop that prints the
count of each Winal in a Tun, using a variable in the print statement.
16. Nest the kin loop inside of the Winal loop and modify the print statement so that it has 2
variables: one for the kin and one for the Winal, printing each kin in each Winal. (ex: 0.1,
0.2, 0.3….17.18)
17. Set the value of each of the variables Tun, Katun, and Baktun and create the nested for
loops to print the Mayan long count from 0.0.0.0.0 to 13.0.0.0.0 .
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
31
Name: _____________________ Date: ___________ Period: ____________
Mayan Long Count KEY
Objective: Apply nested for loops to recreate the Mayan Long Count calendar.
Instructions: Do an internet search (keyword: Mayan Long Count) to answer the questions
below; then follow the steps to create code to display all the dates in the Mayan Long Count
calendar. Note: The word ‘Winal’ may also be spelled ‘Uinal.’
Investigation
1. The word for one day is: Baktun / Katun / Kin /
Tun / Winal
2. The word for 20 days is: Baktun / Katun / Kin / Tun / Winal
3. The word for 18 Winals is: Baktun / Katun / Kin / Tun / Winal
4. The word for 20 Tuns is: Baktun / Katun / Kin / Tun / Winal
5. The word for 20 Katuns is: Baktun / Katun / Kin / Tun / Winal
6. How many days would be in one Tun? 1 / 20 / 360 / 7200
7. Write these in order from least to greatest (Baktun / Katun / Kin / Tun / Winal )
a. _ _ Kin _ _ _
b. _ _ Winal_ _ _
c. _ _ Tun _ _ _
d. _ _ Katun_ _ _
e. _ _ Baktun_ _
8. How many days are there in one year according to our calendar?
30 / 200 / 365 / 410 / 500
9. According to our clock, there are 24 hours in a full day. One second less than a full day
would be 23 hours, 59 minutes, and 59 seconds.
10. If the Long Count date for 14 Aug 3114 BC is 0.0.0.0.0, what is the date for 16 Aug 3114
BC? _ _ _ 0.0.0.0.2 _ _ _
11. If the Long Count date for 14 Aug 3114 BC is 0.0.0.0.0, what is the date 20 days later? _
_ _ _0.0.0.1.0_ _ _
12. If the Long Count date for 21 Dec 2012 is 13.0.0.0.0, what is the date for 20 Dec 2012 ?
_ _12.19.17.19.19 _ _
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
32
Coding Instructions- Modify the file LongCount.java to do the following:
13. Set the variable Kin to the correct integer value to control a for loop that counts from 0 to
19.
14. Create a for loop that prints each Kin in a Winal ( ex: 0, 1, 2, … 19)
15. Set the variable Winal to the correct integer value to control a for loop that prints the
count of each Winal in a Tun, using a variable in the print statement.
16. Nest the kin loop inside of the Winal loop and modify the print statement so that it has 2
variables: one for the kin and one for the Winal, printing each kin in each Winal. (ex: 0.1,
0.2, 0.3….17.18)
17. Set the value of each of the variables Tun, Katun, and Baktun and create the nested for
loops to print the Mayan long count from 0.0.0.0.0 to 13.0.0.0.0 .
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
33
Name: _____________________ Date: ___________ Period: ____________
For Loop Test
Objective: Students identify and practice recently learned for loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
1. j+=7 Is the abbreviation of j = j + 7 Write abbreviated math operations for
*3.
_________
j= j
2. j*=max Is the abbreviation of j = j * max Write abbreviated math operations for j = j /
min ____________
3. for( int j = 0; j < 4 ; j++) Counts from 0 to 3. Write a loop that counts from 0 to 18.
________________________
4. for(int k = 3; k <= 7 ; k++) Counts from 3 to 7. Write a loop that counts from 13 to 27.
______________________
5. for(int k = 100; k >= 1; k - -) Counts backward from 100 to 1. Write a loop that counts
backwards from 27 to 5.
_________________________
6. for(int j = 0; j < 21; j+=2) Counts from 0 to 20 by 2’s. Write a loop that counts
backwards from 21 to 3 by 3’s. ____________________________
7. What does the following code print? for (int k = 8; k> -2; k-=2) System.out.print(k + “
“);
a. 8 6 4 2 0
b. 8 6 4 2 0 -2
c. -2 0 2 4 6 8
8. What does the following code print? for (int k = 2; k<=16; k*=k) System.out.print(k +
“ “);
a. 2 4 6 8 10 12 14 16
b. 2 4 16
c. 2 4 8 16
9. In the for loop for (int x = 0; x < 12; x+=3), the condition is [int x = 0
].
/
x < 12
/ x+=3
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
34
Use the following code for the questions below
// # A
int a = 0;
for (a = 3;a < 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
System.out.println("\n#2");
int b = 0;
for (b = 3;b > 9; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
System.out.println("\n#3");
for (int c = 1;c > -6; c -=3)
System.out.print(" " + c);
// #D
System.out.println("\n#4");
for (int d = 1;d > -6; d +=3)
System.out.print(" " + d);
10. The code in #A prints which?
a) 3 6 9
b) 3 6
c) 3
d) Nothing
e) An infinite loop
11. The code in #B prints which?
a) 3 6 9
b) 3 6
c) 3
d) Nothing
e) An infinite loop
12. The code in #C prints which?
a) 4
b) 1 -2 -5
c) Nothing
d) An infinite loop
13. The code in #D prints which?
a) 4
b) 1 -2 -5
c) Nothing
d) An infinite loop
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
35
Name: _____________________ Date: ___________ Period: ____________
For Loop Test KEY
Objective: Students identify and practice recently learned for loop concepts and skills.
Instructions: Use the examples below to complete the other for loops.
10. j+=7 Is the abbreviation of j = j + 7 Write abbreviate math operations for
j*=3
j= j *3.
11. j*=max Is the abbreviation of j = j * max Write abbreviated math operations for j = j /
min j/=min
12. for( int j = 0; j < 4 ; j++) Counts from 0 to 3. Write a loop that counts from 0 to 18.
for(int j = 0; j<=18; j++)
13. for(int k = 3; k <= 7 ; k++) Counts from 3 to 7. Write a loop that counts from 13 to 27.
for(int k= 13;k<=27; k++)
14. for(int k = 100; k >= 1; k - -) Counts backward from 100 to 1. Write a loop that counts
backwards from 27 to 5.
for (int k= 27; k>=5;k--)
15. for(int j = 0; j < 21; j+=2) Counts from 0 to 20 by 2’s. Write a loop that counts
backwards from 21 to 3 by 3’s. for (int j = 21; j>=3; j-=3)
16. What does the following code print? for (int k = 8; k> -2; k-=2) System.out.print(k + “
“);
a. 8 6 4 2 0
b. 8 6 4 2 0 -2
c. -2 0 2 4 6 8
17. What does the following code print? for (int k = 2; k<=16; k*=k) System.out.print(k +
“ “);
a. 2 4 6 8 10 12 14 16
b. 2 4 16
c. 2 4 8 16
18. In the for loop for (int x = 0; x < 12; x+=3), the condition is [int x = 0
].
/
x < 12
/ x+=3
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
36
Use the following code for the questions below
// # A
int a = 0;
for (a = 3;a < 9; a +=3)
System.out.print(" " + a);
System.out.print(" " + a);
// #B
System.out.println("\n#2");
int b = 0;
for (b = 3;b > 9; b +=3)
System.out.print(" " + b);
System.out.print(" " + b);
// #C
System.out.println("\n#3");
for (int c = 1;c > -6; c -=3)
System.out.print(" " + c);
// #D
System.out.println("\n#4");
for (int d = 1;d > -6; d +=3)
System.out.print(" " + d);
14. The code in #A prints which?
a) 3 6 9
b) 3 6
c) 3
d) Nothing
e) An infinite loop
15. The code in #B prints which?
a) 3 6 9
b) 3 6
c) 3
d) Nothing
e) An infinite loop
16. The code in #C prints which?
a) 4
b) 1 -2 -5
c) Nothing
d) An infinite loop
17. The code in #D prints which?
a) 4
b) 1 -2 -5
c) Nothing
d) An infinite loop
IT: [Computer Programming]: [For Loops] Plan
Copyright © Texas Education Agency, 2013
37
© Copyright 2025 Paperzz