PowerShell Increment and Decrement Operator


The following are increment and decrement operators in powerShell, example for pre and post increment or decrement, whether you can perform pre-post increment or decrement. But it's really different. Try to understand the code below

$n = 1

# post increment
$a = $n++ # a = 1, n = 2
Write-Host $a $n

# pre increment
$a = ++$n # a = 3, n = 3
Write-Host $a $n

# post decrement
$a = $n-- # a = 3, n = 2
Write-Host $a $n

# pre decrement
$a = --$n # a = 1, n = 1
Write-Host $a $n

Notice the different pre-post increment and decrement. Think about it. Hope the example above can make you understand. Easy right! Leave comment if you guys have feedback and questions.

Subscribe to receive free email updates:

0 Response to "PowerShell Increment and Decrement Operator"

Post a Comment