Caché Basic Reference
Increment

 Server:docs2 Instance:LATEST User:UnknownUser

 [ Home ]  >  [ Caché Development References ]  >  [ Caché Basic Reference ]  >  [ Caché Basic Functions ]  >  [ Increment ] Go to: Description Examples Search:

Atomically increments the value of a variable and returns the new value.
Synopsis
`Increment(varname[,change])`
Arguments
 varname The name of the variable to be incremented (or decremented). change Optional — A numeric that specifies by how much the value should be incremented. The value of change can be negative for decrements. This value can be a fractional number. If specified as 0 (zero), no increment or decrement occurs. If not specified, varname is incremented by 1.
Description
The virtual machine ensures that during the increment the variable is locked and after the increment unlocked. Because of the atomic nature of this function, this operation is very efficient especially in network environments.
Examples
The following example demonstrates the use of the Increment function:
```^PersonRecords = 1000
NewPersId = Increment(^PersonRecords)
Println NewPersId 'prints 1001
NewPersId = Increment(^PersonRecords, 10)
Println NewPersId 'prints 1011```

The following example demonstrates the use of the Increment function to decrement a number:
```countdown = 10
While countdown > 0
Println countdown
countdown = Increment(countdown,-1)
Wend
Println "Blast off!"```

The following example demonstrates the use of the Increment function with a fractional value to represent successive sevenths of a circle:
```angle = 0
sevenths = 51.428572
While angle < 360
angle = Increment(angle,sevenths)
Println angle," degrees"
Wend```

 Copyright © 1997-2017, InterSystems Corp. [Back]    [Home]    [Top of Page]   [Next] Build: Caché v2017.1.1 (111) Last updated: 2017-05-17 15:19:51 Source: RBAS_fincrement.xml