Foundations of Technology
Introduction to Computer Science Principles byDesign
Unit 1: Computer Science Principles byDesign
Learning Cycle 3: Logic: If/Else, Loops, AND, OR, NOT (Microbit)
Foundations of Technology
2
Big Idea
In this presentation we will learn how to use If/Else, Loops, AND, OR, NOT in programing the microbit to solve engineering problems.
Foundations of Technology
3
What is a Logic?
Foundations of Technology
4
Logic blocks
There are three groups of blocks under the logic:
Conditionals: If/else
The statements inside the if block
will be executed only when the value
inside the hexagon is “TRUE”
5
Example: Conditional
if the boolean statement is
true, the LED will appear
in the left,
Otherwise, it stays
in the center
6
Logic Blocks
Comparisons:
Use comparator operators
to evaluate whether the
comparison is true or false.
=, >,<, ≥, ≤,≠
7
Example: Comparison
The boolean statement
is false so the else is
executed
8
Logic Blocks
Boolean:
Using the logical operators AND, OR,
NOT to evaluate expressions (whether
TRUE or FALSE
(Boolean is the technical term for a
data type that can only be true
or false
9
Example: Boolean
True and True will return
a true
10
Truth tables for AND, OR, NOT
11
AND | TRUE | FALSE |
TRUE | TRUE | FALSE |
FALSE | FALSE | FALSE |
OR | TRUE | FALSE |
TRUE | TRUE | TRUE |
FALSE | TRUE | FALSE |
NOT TRUE | FALSE |
NOT FALSE | TRUE |
Example: Boolean
True and False will return
a False
12
Example: Try this Program
Initialize the variables
score and Goal
When button A is
pressed, score increases
by 1.
When score equals Goal,
servo moves to 135 and
microbit displays smiley face,
otherwise, servo stays at 90.
13
Example: Try this Program
Initialize the variables
score and Goal
When button A is
pressed, score increases
by 1
When score equals Goal,
servo moves to 135 and
microbit displays smiley face,
otherwise, servo stays at 90
14
Loops
Repetition (iteration) of a command/statement or a group of commands/statements
15
Loops
Repetition can be
controlled by a boolean
or a number/index
16
Loops
Repetition can be
controlled by a boolean
or a number
17
Try this:
18
Example of Possible Solution
19