English

Variables & Loops

Storage and Repetition

A 'variable' is like a labeled box where you store data (like numbers or text). A 'loop' is a way to tell the computer to repeat an action multiple times without writing the same code over and over.

score
10
Variable Box

Real-world Examples

  • Variable: A bank account balance that changes.
  • Loop: Dealing 5 cards to each player.

3 Core Concepts

1. Declaration

Creating a variable (e.g., let score = 0;).

2. Assignment

Updating the variable (e.g., score = score + 10;).

3. Iteration

Running a block of code multiple times (e.g., for loop).

Robot Loop Simulator

Change the number of steps and watch the robot execute the loop!

3
Code
let steps = 3;
for (let i = 0; i < steps; i++) {
robot.moveForward();
}
Awaiting execution...
0
1
2
3
4
5
6
7
🏁

Quick Drill

Test your logic!

Q: What does 'let x = 5;' do?
Google AdSense Area