Close
Searching...
Close full mode

Conditional Statements

Summary

Materials

Instructional Activities and Classroom Assessments

  1. Boolean and Relational Operators Review (5 minutes)
  2. Conditional Statements (5 minutes)
  3. Create a Program (40 minutes)
  4. Homework

Learning Objectives

  • CRD-2.B Explain how a program or code segment functions. 4.A
  • CRD-2.G Describe the purpose of a code segment or program by writing documentation. 4.A
  • AAP-1.A Represent a value with a variable. 3.A
  • AAP-2.G Express an algorithm that uses selection without using a programming language. 2.A
  • AAP-2.H For selection: a.) Write conditional statements. 2.B b.) Determine the result of conditional statements. 4.B

Essential Knowledge

  • CRD-2.A.1 The purpose of computing innovations is to solve problems or to pursue interests through creative expression.
  • CRD-2.B.2 A code segment is a collection of program statements that is part of a program.
  • CRD-2.G.3 Programmers should document a program throughout its development.
  • AAP-1.A.1 A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.
  • AAP-1.A.2 Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.
  • AAP-2.G.1β€―Selectionβ€―determines which parts of an algorithm are executed based on a condition being true or false.β€―
  • AAP-2.H.1 Conditional statements, or β€œif-statements,” affect the sequential flow of control by executing different statements based on the value of a Boolean expression.
  • AAP-2.H.2 The exam reference sheet provides
    • Text: IF(condition) { <block of statements> }
    • Block: IF condition block of statements in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.

Details

1. Booleans and Relational Operators Review (5 minutes)

  • What is a Boolean value?
    • Variable that can only be true/false.
  • How do you test if a Boolean variable is true/false?
    • Use an if statement.
    • Explain conditional statements.
  • What is another way to define something as true or false?
    • Relational operators.
    • Relational operators are used to test the relationship between two variables, expressions, or values.
    • A comparison using a relational operator evaluates to a Boolean value.

2. Conditional Statements (5 minutes)

  • Discuss the conditional statements on the exam reference sheet.
  • Review the if and if-else statement used in our lesson yesterday.
  • Code tracing for Drive or Bike User Input program.
  • Define nested conditionals.

3. Putting it all Together Project (40 minutes)

  • Review the requirements for the Putting it all together Project.
  • Students will create a program that:
    • Asks for user input.
    • Incorporates the use of string, integer, and Boolean variables.
    • Uses relational operators.
    • Incorporates conditional statements.

4.Homework

  • Students will do the following for homework:
    • Take a screenshot of their code segment.
    • Create a screencast of their program running.
    • Answer the following questions:
      • What is the purpose and function of their program?
      • What is the input and output of their program?
      • Explain what the nested conditional in the program does.
  • Students will enter all of their work on the Putting it All Together Project page.