Lesson 12: Conditionals in Farmer
Conditionals | Farmer
This lesson introduces students to
while loops and
if / else statements. While loops are loops that continue to repeat commands as long as a condition is true. While loops are used when the programmer doesn't know the exact number of times the commands need to be repeated, but the programmer does know what condition needs to be true in order for the loop to continue looping.
If / Else statements offer flexibility in programming by running entire sections of code only if something is true, otherwise it runs something else.
A basic understanding of conditionals is a recommended prerequisite for Course E. We created this introduction to give a review for the students already familiar to conditionals and allow practice for the students that are just learning. If you find that the understanding of conditionals varies widely in your classroom, we recommend a strategic pairing of students when completing this online lesson.
Warm Up (15 min)
Main Activity (30 min)
Wrap Up (15 min)
Students will be able to:
- Define circumstances when certain parts of a program should run and when they shouldn't.
- Determine whether a conditional is met based on criteria.
- Play through puzzles in Course E Online Puzzles - Website to find any potential problem areas for your class.
- Review CS Fundamentals Main Activity Tips - Lesson Recommendations.
- Make sure every student has a Think Spot Journal - Reflection Journal
For the Teacher
For the Students
- Think Spot Journal - Reflection Journal
- Condition - A statement that a program checks to see if it is true or false. If true, an action is taken. Otherwise, the action is ignored.
- Conditionals - Statements that only run under certain conditions.
- While Loop - A loop that continues to repeat while a condition is true.
Warm Up (15 min)
Gather the class together and ask two volunteers to walk straight in some direction in the classroom. If they encounter a chair out of place, they must step over it. If they reach a wall, they must sit down.
Once all of the students are sitting down, ask how you would program a robot to respond to a wall or a chair. Remind students that you cannot simply say "Step over chair" unless you know there is a chair, and you will not always know there is a chair. It might be helpful to translate the task into instructions like:
- while there is a path ahead
- walk forward
- if there is a chair, step over it
- sit down
Tell students they will be using conditionals to solve this problem on Code.org. Give the definition of:
- Condition: A statement that a program checks to see if it is true or false. If true, an action is taken. Otherwise, the action is ignored.
- Conditionals: Statements that only run under certain conditions.
Open up a discussion of when you might use a conditional in your code.
Main Activity (30 min)
The patterns in these puzzles may not be obvious to every student. We recommend that you play through these levels beforehand to best understand any problem areas for your class. Also, watching and using the techniques from Pair Programming - Student Video may be helpful for your class.
Wrap Up (15 min)
Having students write about what they learned, why it’s useful, and how they feel about it can help solidify any knowledge they obtained today and build a review sheet for them to look to in the future.
- What was today's lesson about?
- How do you feel about today's lesson?
- What is a conditional? Why would you program a conditional?
- Give an example of using a conditional during your day? (ex. If I am hungry, I eat some food; While I am walking across the street, I keep an eye out for cars)
While We Play
Gather the class for some fun outside or in a gym with a ball! This could be done in a circle or as a team in a court
- While the ball is in play, we must all be ready to hit it
- If the ball is hit to you, you must keep it in the air
- If you hit the ball once, you cannot hit it again (only one touch per person per turn, no double hitting)
- If the ball goes out of bound, every student must fall to the ground dramatically. The last kid to fall has to retrieve the ball.
At the end of the first round, ask the students if they can identify the conditionals in the game. Can they come up with others they might want in the game?
CSTA K-12 Computer Science Standards
AP - Algorithms & Programming
- 1B-AP-11 - Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process.
This list represents opportunities in this lesson to support standards in other content areas.
Common Core English Language Arts Standards
L - Language
- 4.L.6 - Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases, including those that signal precise actions, emotions, or states of being (e.g., quizzed, whined, stammered) and that are basic to a particular topic (e.g
SL - Speaking & Listening
- 4.SL.1 - Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 4 topics and texts, building on others’ ideas and expressing their own clearly.
Common Core Math Standards
MP - Math Practices
- MP.1 - Make sense of problems and persevere in solving them
- MP.2 - Reason abstractly and quantitatively
- MP.4 - Model with mathematics
- MP.6 - Attend to precision
- MP.7 - Look for and make use of structure
- MP.8 - Look for and express regularity in repeated reasoning
NBT - Number And Operations In Base Ten
- 4.NBT.4 - Fluently add and subtract multi-digit whole numbers using the standard algorithm.
Next Generation Science Standards
ETS - Engineering in the Sciences
ETS1 - Engineering Design
- 3-5-ETS1-1 - Define a simple design problem reflecting a need or a want that includes specified criteria for success and constraints on materials, time, or cost.
- 3-5-ETS1-2 - Generate and compare multiple possible solutions to a problem based on how well each is likely to meet the criteria and constraints of the problem.