EZ Math Movie, Tutorials, Mathematics, Increment, Decrement


Increment means 'add to'. It often means 'add 1 to'. For starters, we will talk about adding 1 to the value held by a variable. We will be 'incrementing the value by 1', or 'incrementing the variable by 1', or often, simply, 'incrementing the variable'.

When you are counting by 1's with a variable, a very handy way to increment it by 1 is this way:


The above line will change the value of x by adding 1 to it. You will note in the Language section of this site, the EZ Math Movie language is an extension of the JavaScript language, and in the JavaScript language this statement has more power and use than we are explaining here. However, for our purposes concerning exploring mathematics, knowing that this statement will increment a variable by 1 is enough for now.

Another way to increment.

You can also add 1 to a variable, say x, in this way:

x += 1;

Note the 'plus equals' operator, +=, in this statement. This operator will take the current value of x and, in this case, add 1 to it.

You can increment a variable by any amount this way. For example, the following code changes the value of x by adding 5 to it:

x += 5;

Yet another way to increment.

There is another way to increase the value of a variable:

x = x + 1;

Here's how it works:

This method can also be used to add any value to x. Here's an example of adding 7 to x:

x = x + 7;

Decrement three ways.

Subtracting from, or decrementing, a variable is a lot like incrementing a variable. First, a simple method to subtract 1 from a variable, say x:


Next, a method to subtract 1 or any other value from a variable:

x -= 1;


x -= 5;

Finally, you can decrement this way:

x = x - 1;


x = x - 7;

Running the example program

The example program demonstrates all the ways described here to increment and decrement a variable. Note the handy use of the printStatement command to output the values for x.

The example program

Angle measurement: Degrees Radians

Go on input

Sorry, apparently this browser does not support HTML 5 canvas tag graphics.

Edit: Runtime          View: Starter Suggestion

To runtime:


Editor width: Normal Wide








Next tutorial: Trigonometry

All contents of EZ Math Movie are copyrighted: Copyright 2011, Edward A. Zobel. All rights reserved.

Other sites you may find interesting

Zona Land Education Like Math and Physics?

Zona Land Education offers explanations, diagrams, and animations on these topics.
And it is all presented in a clear and casual manner.

Here is the link: zonalandeducation.com

EZ Programing Demos Want to learn about programing computers?

EZ Programing Demos has an animated, slow motion, interactive programing language demonstrator.
The site presents basic ideas at a beginner's level.

Here is the link: ezprogramingdemos.com

Custom Search