Learning Rooms/△ Level 2 · Builder/Computing and algorithms
Programming Basics: Statements & Functions: Crash Course Computer Science #12
CrashCourse · Length: see YouTube · captions on YouTube · nothing loads until you press play
By the end you can…
- Read and write IF–THEN–ELSE rules that use a sensor reading.
- Decide which branch runs for a given reading.
- Explain why every rule needs an ELSE (or a deliberate 'do nothing').
Watch it all: no segment has been checked by hand for this video yet.
1.Predict before you press play
Rule: IF distance < 20 cm THEN stop ELSE drive. The sensor reads exactly 20 cm. What does the robot do?
Pick one before you press play. A wrong guess is fine: it is what makes the video stick.
2.See the idea first
Play with this diagram for a minute. It gives you something to hang the video on.
Loading the interactive…
Can't use the diagram? Read a description instead
The rule tester can be replaced by this table for the rule IF distance < 20 cm THEN stop ELSE drive: 5 cm → stop; 19 cm → stop; 20 cm → drive; 21 cm → drive; 60 cm → drive; 100 cm → drive.
3.Watch, actively
Walks through if-statements, while loops and for loops with a simple game, the same building blocks this term uses.
Length: see YouTube · captions on YouTube · source
Nothing loads from YouTube until you press play.
Watch for…
- → Watch for the if-statement in the game example: a condition that is true or false, and code that runs only in one case.
- → Watch for the for loop: code that runs a set number of times.
Pause whenever you like. Rewatching a hard minute is a good habit, not a failure.
Can't stream it? Read the idea instead
Programs are built from a few kinds of statement: an if runs code only when a condition is true, a loop repeats code, and a function packages steps under a name so they can be reused. Those three ideas cover most of what a simple robot program does.
What the video covers (our own note, written when we verified it): Walks through if-statements, while loops and for loops with a simple game, the same building blocks this term uses.
Written by Tactiverge in our own words, not a transcript. The full lessons below explain the idea without the video.
Jot down one thing that surprised you and one question you still have.
4.Practise what you just saw
These come from the lessons that use this video and are checked on the server. Wrong answers get a hint and another try.
Practice 1
IF light level < 30 THEN lamp on ELSE lamp off. The sensor reads 45. What happens?
Practice 2 · a fresh version every time
x starts at 8. A loop runs "x = x + 2" exactly 6 times. What is x when the loop ends?
Practice 3
IF speed > 50 THEN beep. The speed is exactly 50. Does it beep?
Practice 4 · a fresh version every time
x starts at 2. A loop runs "x = x + -1" exactly 4 times. What is x when the loop ends?
5.Try it yourself
No simulation models this idea yet. The lessons below have an interactive diagram instead.
6.Build something with it
Follow-up project
Write IF–THEN–ELSE rules for a smart bin: it opens when a hand is within 15 cm and closes otherwise. Test your rule at 10, 15 and 20 cm. Did 15 cm do what you wanted? If not, change < to ≤.
Where this video lives
- IF this, THEN that, ELSE the other · Level 1, week 22
- Repeat N times · Level 1, week 23
In the course catalogue: CSE-101 Algorithms without code
The video is by CrashCourse, embedded from YouTube with privacy-enhanced mode and never autoplayed. The room around it (prompts, notes, practice, projects) is Tactiverge's, written with AI assistance and checked by automated tests only.