Table of Contents

Auto(de|in)crements

If you want to add 1 to a variable you can, logically, do this; $num=$num+1 . There is a shorter way to do this, which is $num++. This is an autoincrement. Guess what this is; $num-- . Yes, an autodecrement.

This example illustrates the above:

$num=10;
print "\$num is $num\n";

$num++;
print "\$num is $num\n";

$num--;
print "\$num is $num\n";

$num+=3;
print "\$num is $num\n";
   

The last example demonstrates that it doesn't have to be just 1 you can add or decrease by.