EZ Programing Demos

Slow motion, step by step, animated demonstrations of basic computer programing techniques

Links to topics:

Current topic:

Printing the value of a variable

A computer programing language can also print the value of a variable. Here we use the term 'variable' to mean the same as one would use the term in Algebra. That is, a variable is a symbol that is a letter of the alphabet, and it holds a value that is a number.

In computer languages you could see a line of code that would look something like this:

    
    x = 5
    

This is called an assignment statement. The x is the variable that is being assigned a value. It is here assigned the value 5.

An assignment statement at EZ Programing Demos is shown with the let command. So if it were typed out, it would look like this:

    let x = 5

If you wanted to print the value of a variable, the name of the variable would be included in the print statement, as in:

    print x

Play with the included programing demonstration. Change the number in the let command to understand how you may alter the value assigned to the variable. Change the name of the variable both in the let command and in the print command to understand that you must print the same variable name to which you assigned a value.

 Slow  Medium  Fast 
Click 'Run' to go.

Understand that there is a difference between printing a letter of the alphabet and printing the value of a variable. Most computer languages take this into account.

If you want to print a letter of the alphabet, say 'b', then you would use a programing line like this:

    print "b"

Note the quotes in the above line.

However, if you were doing some math with a variable named b, and you wanted to print the number that represented the value of the variable b, then you would use a programing line like this:

    print b

Note the lack of quotes in the above line.

 

The flowchart for this program:

 

Imaginary language code:

    
    x = 5;
    
    print(x);
    

 

Suggested next article:

EZ Math Movie is a site that can help you experiment with and understand many topics in mathematics. Its main feature is an interactive animated (x, y) graph that you control with an actual programing language. There are many examples and tutorials, and EZ Math Movie is crossed referenced with both EZ Programing Demos and Zona Land Education.

 

Zona Land Education is a site with explanations and interactive diagrams covering many topics in physics and mathematics. Zona Land Education is cross referenced with EZ Math Movie, and it contains several animations that use EZ Math Movie's programing language.