Lesson 12: Conditionals in Farmer

Conditionals | Farmer

Overview

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.

Purpose

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.

Agenda

Warm Up (15 min)

Main Activity (30 min)

Wrap Up (15 min)

Extended Learning

Objectives

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.

Preparation

Links

Heads Up! Please make a copy of any documents you plan to share with students.

For the Teacher

Vocabulary

  • 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.

Support

Report a Bug

Teaching Guide

Warm Up (15 min)

Introduction

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)

Course E Online Puzzles - Website

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)

Journaling

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.

Journal Prompts:

  • 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)

Extended Learning

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

Rules:

  • 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?

Standards Alignment

View full course alignment

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.