What make $x += 100 different from $x = $x + 100?

Here’s the sample

PS> $fn_using_short_form = { $x += 100;     $x }
PS> $fn_using_long_form  = { $x = $x + 100; $x }
PS> $x = 5

PS> &$fn_using_short_form
100

PS> &$fn_using_long_form
105

BTW, I’ve tried asking ChatGPT, Claude, and Gemini. I can confirm that LLMs are really not something to be trusted on :smile:

Hi, welcome to the forum :wave:

This is explained in the help:

See the section ‘Using compound assignment operators’.

1 Like

Oh. Thanks. You just destroyed my hope to have been discover PowerShell bug :rofl:
Cheers.

LLMs, e.g. ChatGPT, CoPilot, Gemini, etc. are great for creating rough drafts or starting code fragments but fall very short when it comes to the finer points\nuances. For example, students are permitted to use calculators during Algebra\Geometry exams; but if they don’t have a firm grasp of the logic\theory involved then calculators are worthless. :wink:

I use LLMs quite a bit during script creation. Real basic, I sketch out what I want the script to do in pseudo-code, which I then paste into the LLM with a request for raw code generation in whatever language the eventual script is to be written. Then comes the fun part: Copy and paste this raw code into Visual Studio Code and beat it into functional submission. :slightly_smiling_face: