++

The ++ symbol is used to increment a variable, i.e. add 1 to it. It can be used either in preincrement or postincrement mode. In preincrement mode, the value of the variable is increased by one, then used in an expression. In postincrement mode, the value of the variable is used in the expression, then incremented by one. For example

routine test
{
local i,j,k

   i = 5
   j = ++i   ! Line 6
   k = i++   ! Line 7
   print "i="; i ;" j="; j++ ;" k " ! line 8
   k = 9
   j = 8
   i = k++ + j
   print "i="; i ;" j="; j ;" k " ! line 12
   k = 9
   i = ++k + j
   print "i="; i ;" j="; j ;" k " ! line 15
}

At line 6, i and j will both be equal to 6. At line 7, k will also equal 6, but the value of i will be 8. However, on line 8, j will display as being equal to 6, but after the line is printed, j will be 7. At line 12, i will show as 17, but k will be shown as 10. At line 12, i will show as 18, and k will show as 10.

See Also: --