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

**URL:** <https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625>\
**Category:** PowerShell Help\
**Created:** [August 24, 2024, 3:05pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625 "2024-08-24T15:05:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sake/32/5626_2.png) [@sake](https://forums.powershell.org/u/sake)\
**Post date:** [August 24, 2024, 3:05pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/1 "2024-08-24T15:05:55Z")

</div>

Here’s the sample

```auto
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

```

---

<div class="post-metadata">

**Author:** ![sake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sake/32/5626_2.png) [@sake](https://forums.powershell.org/u/sake)\
**Post date:** [August 24, 2024, 3:23pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/2 "2024-08-24T15:23:55Z")

</div>

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

> **[ChatGPT](https://chatgpt.com/share/76f2d20b-b9d2-42eb-aed7-22643cbe3bdd)**
>
> A conversational AI system that listens, learns, and challenges

> **[‎Gemini - += vs = in PowerShell](https://gemini.google.com/share/00df6db5f426)**
>
> Created with Gemini

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [August 24, 2024, 3:55pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/3 "2024-08-24T15:55:01Z")

</div>

Hi, welcome to the forum 👋

This is explained in the help:

> **[about Assignment Operators - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_assignment_operators?view=powershell-7.4)**
>
> Describes how to use operators to assign values to variables.

See the section ‘Using compound assignment operators’.

---

<div class="post-metadata">

**Author:** ![sake](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/sake/32/5626_2.png) [@sake](https://forums.powershell.org/u/sake)\
**Post date:** [August 24, 2024, 10:12pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/4 "2024-08-24T22:12:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pendraig](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/pendraig/32/5631_2.png) [@Pendraig](https://forums.powershell.org/u/Pendraig)\
**Post date:** [August 26, 2024, 3:13pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/5 "2024-08-26T15:13:45Z")

</div>

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. 😉

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [September 25, 2024, 3:14pm UTC](https://forums.powershell.org/t/what-make-x-100-different-from-x-x-100/24625/6 "2024-09-25T15:14:30Z")

</div>

Closed on September 25, 2024, 3:14pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
