Logic in Loops
Summary
Materials
- Day 7 PowerPoint Deck
- Logic in Loops Handout
- Logic in Loops Handout in Word
- Logic in Loops Unplugged
- Sentence Puzzles
- Decks of cards
- Dice
- Tape
- guessingGame (for teacher)
- Activity: Logic in Loops
Instructional Activities and Classroom Assessments
- Review Loop and Logic (5 minutes)
- Sentence Puzzles: Logic in Loops Unplugged Activity (10 minutes)
- Introduce Logic in Loops (10 minutes)
- Activity: Logic in Loops (25 minutes)
- Reflection/Homework
Learning Objectives
Essential Knowledge
AAP-2.E.1 A Boolean value is either true or false.
AAP-2.E.2 The exam reference sheet provides the following relational operators: =, β , >, <, β₯, and β€. Text and Block:
Β§ a = b
Β§ a β b
Β§ a > b
Β§ a < b
Β§ a β₯ b
Β§ a β€ b
These are used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to 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.
AAP-2.K.1 Iteration statements change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met.
AAP-2.K.3 The exam reference sheet provides
- Text: REPEAT UNTIL(condition) { <block of statements> }
- Block: REPEAT UNTIL block of statements condition in which the code in block of statements is repeated until the Boolean expression condition evaluates to true.
AAP-2.K.4 In REPEAT UNTIL(condition) iteration, an infinite loop occurs when the ending condition will never evaluate to true.
AAP-2.K.5 In REPEAT UNTIL(condition) iteration, if the conditional evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop.
Details
1. Loops and Logic review (5 minutes)
- Define Loops
- Explain the benefit of loops
- Define logical expression
- Explain the benefit or Boolean arithmetic logical
2. Sentence puzzles: Logic in Loops unplugged activity (10 minutes)
- Direct students to get in groups and play a game with cards and dice.
- Students will describe the process using the concepts of loops and logic.
- Students will write the process in Pseudocode.
3. Introduce Logic in Loops (10 minutes)
- Define conditional statements if, else, when.
- Reinforce students' knowledge regarding iteration.
- Demonstrate using conditional statements.
4. Activity: User Input and String Logic (25 minutes)
- Direct students to go to their Activity: Logic in Loops page.
- Direct students to complete Tasks 1 and 2.
- If students have time, encourage them to use functions and parameters in the fireball game to make it easier to manage and to recreate code segments in JavaScript.
5. Reflection/Homework
If you run out of time, you may also assign this as individual homework. Students should complete their reflection.
- In task #2, you implemented a basic βpassword checker.β What is one possible downside of the way that the code was implemented?
- List at least two ways in which user input could be used in writing a text based game.