Category:Variables

Assigns the input value to a variable.

Variables are used as placeholders for values such as numbers or strings of text. Variables allow for a lot of freedom in programming. Instead of having to type out a phrase many times or remember a number, computer scientists can use variables to reference them. Variable values can change throughout a program.

If no variable with the specified name has been created, this block can create a new named variable with the given value. If the variable already exists, its new value will replace its old value.

Parameters

NameDescription
value input The value the variable is being set to
variable name The name of the variable. The name can be chosen from a drop-down list or customized using the rename option.

Tips

  • Using a descriptive variable name helps best identify a specific variable and makes it easier for anyone else reading the code to understand what is happening.
  • If you decide to change a variable name while working on your project, you don’t have to change all the other matching blocks individually. Choosing to “rename all” variables with that name will automatically rename all the matching blocks used in your project.

Found a bug in the documentation? Let us know at documentation@code.org