Without variables, computers couldn't remember anything—not even your score in a game. Without loops, you would have to write thousands of lines of code just to show a list of items. Together, they are the absolute core of programming logic.
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.
Creating a variable (e.g., let score = 0;).
Updating the variable (e.g., score = score + 10;).
Running a block of code multiple times (e.g., for loop).
A very common error is the 'Infinite Loop'—creating a loop with a condition that never becomes false, causing the program to freeze. Another mistake is trying to access a variable before it has been declared, resulting in a 'ReferenceError'.
Change the number of steps and watch the robot execute the loop!
let steps = 3;
for (let i = 0; i < steps; i++) {
robot.moveForward();
}
Test your logic!
The concept of variables in programming traces back to the 1940s with early computers like ENIAC. The concept of loops was pioneered by Ada Lovelace in the 1840s when she designed an algorithm to calculate Bernoulli numbers using a looping structure for Charles Babbage's Analytical Engine—a century before modern computers existed!