variables

although fig was designed to teach 7 programming concepts, these concepts are common or illustrative to some degree in many, if not all programming languages. learning these concepts will help you understand python, bash, javascript and many others.

variables are a combination of name and value. variable assignment is when a variable is created or updated with a value, such as:

height = 5

in fig, the = is optional and most lines of code begin with a variable. the exceptions to this are for a few special commands, such as the "textmode" command-- which do not share the line with other commands.

height 5
firstname "alan"
lastname "patel"

unlike constants, variables can have their values changed or updated:

height 5
height 6

there is little point in setting height to 5 just to set it to 6 on the next line, but sometimes a program will change the value of a variable somewhere else in the code, if you tell it to.

when you read part of a file, or get input from the keyboard, it is useful to have that input stored in a variable.

unless you write their contents to a file, variables do not get saved when you quit the program. in the above example, the variable "height" has the value of 6 but when the program stops, height will not have any value at all.

variables have type-- this refers to the kind of data (the value) they are storing. 5 is a numeric value, an integer (whole number without fraction or decimal.) 5.5 would be a "float" (number with a decimal point.) fig treats both types as "numeric" collectively.

a value in quotes "like this" is called a string-- a string of characters. this is a value that can hold letters, numbers, punctuation and spaces-- along with a few other characters like "tab."

another variable type is the array-- while most variables associate a single name with a single piece of data, an array associates a single name with zero, one or multiple pieces of data.

setting variables is one of the 7 most important concepts in fig, but by themselves, variables are not very useful without input, output, basic-math, loops and conditionals.

- license: creative commons cc0 1.0 (public domain)

http://creativecommons.org/publicdomain/zero/1.0/