ELI5: Explain Like I'm 5

Control variable (programming)

Imagine you are playing with blocks, building a tower. You have different colors of blocks, and sometimes you want to see how height of tower changes when you use different color of blocks.

Now imagine you have a robot who can do this for you automatically. You tell it to build the tower using red blocks, and it measures the height. Then you tell it to build using blue blocks, and again measures the height.

The difference here is that you want to make sure that the only thing that changes is the color of the blocks, no other factors. For example, you want to make sure that the robot always uses the same number of blocks, and builds the tower in the same way each time.

In a similar way, in programming, a control variable (also known as a parameter) is something that you deliberately change to see how it affects your program, while keeping everything else constant. You want to make sure that the only thing that changes in your program is the control variable.

For example, let's say you're making a video game and you want to see how fast a character moves in different scenarios. You could create a control variable called "speed" and then set it to different values (e.g. 5, 10, 20, etc.) to see how the character moves at different speeds. But you want to make sure that everything else in the game (e.g. the surroundings, the rules, the obstacles, etc.) remains the same each time you change the speed.

In summary, a control variable in programming is something that you change deliberately to see how it affects your program, while keeping everything else constant.