![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Subexpressions and Unary Operators Hi I'm trying to work out the difference in the behaviour of $() and () - in particular with regard to unary operators, and would appreciate any insights on the matter. #These statements work as expected .... $i=3; Write-Host ($i++) $i=3; Write-Host (++$i) #but these show no output $i=3; Write-Host $($i++) $i=3; Write-Host $(++$i) $i=3; $i++ $i=3; ++$i #whereas these do ... $i=3; Write-Host $(($i++)) $i=3; Write-Host $((++$i)) Any thoughts? -- Jon |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Subexpressions and Unary Operators "Jon" <Email_Address@xxxxxx> wrote in message news:OvU36gLfIHA.2000@xxxxxx
basically comes down to PowerShell making assumptions about whether or not you want to see the result of an increment/decrement operation. Most of the time you don't. However () is special since you can only have one expression in it and if they followed their normal rules then ($i++) wouldn't output anything. The language designers figured that would be "unexpected" in this scenario so they make an exception. HTH, Keith | ||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: Subexpressions and Unary Operators "Keith Hill [MVP]" <r_keith_hill@xxxxxx_spam_I> wrote in message news:E71EA756-D026-4A25-A642-4F9096F4D22A@xxxxxx
Thanks Keith - one of the books on my "to read " list. It sounds like it's been reasoned through then. It's slightly different from what I've experienced in other languages, hence the question. I suppose as it stands now, the flexibility is there to either output or not output as you choose. Hopefully that flexibility will remain, since it's a useful construction with commands like Write-Host - otherwise you're forced to use roundabout techniques like $var = 3; $var = $var + 1 Write-Host "Var is now $var" #More compact, as you can now, to be able to write $var = 3 Write-Host "Var is now $((++$var))" albeit a little unintuitive. -- Jon | ||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Subexpressions and Unary Operators "Jon" <Email_Address@xxxxxx> wrote in message news:u5Dew#LfIHA.4712@xxxxxx
$var = 0 Write-Host "$($var++;$var)" which is bit easier to understand. -- Keith | ||||||||||||
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CTP2 comparison operators | Steve | PowerShell | 2 | 5 Days Ago 02:14 PM |
| $(subexpressions) again... | Hans Dingemans | PowerShell | 4 | 02-13-2008 10:45 AM |
| Any possibility for boolean operators in message rules? | geggytah | Vista mail | 2 | 05-14-2007 01:12 PM |
| PowerShell User Guide - Comparison Operators - error? | =?Utf-8?B?RGF2aWQgSyBBbGxlbg==?= | PowerShell | 1 | 08-28-2006 04:04 PM |
| Bit Operators | Wrighty | PowerShell | 8 | 07-04-2006 02:52 PM |