Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function #2271

Conversation

og-mrk
Copy link
Contributor

@og-mrk og-mrk commented Jul 4, 2024

Why change it to a simple For Loop?

because I couldn't find a way to change the variable $x on each iteration of the ForEach loop (and no it isn't because the x is capital in $X++.. already tried changing this, but to no avail ...)

So I've changed it to be a simple "C Like" For Loop, which has a variable $i initialized to the value of 0, and on each iteration it'll increase by one (the $i++ part).

If anyone can find a better solution then this.. then I welcome anyone to do so, and open a PR for it 👍

Issues this PR tries to resolve

Resolves: #2233

@og-mrk og-mrk changed the title Change Main from 'ForEach' into a 'For' loop inside 'Install-WinUtilProgramWinget' Private Function Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function Jul 4, 2024
@og-mrk og-mrk force-pushed the function-improvement/installwinutilprogramwinget-2024-07-05 branch from c8928c5 to 5b75013 Compare July 4, 2024 23:21
@Marterich
Copy link
Contributor

Marterich commented Jul 5, 2024

Info:
If you desperately want to force the "Powershell way" or doing things, you could probably use a ForEach loop with the $list.indexof($_) function to get the element number and therefore a counter.
But, as this is most definitely way more resource intensive (running a function to query the index of a PSObject vs running a simple binary operation to increment the counter) and also not much more readable, I prefer the "c" way at the moment

@ChrisTitusTech ChrisTitusTech merged commit d7c2e2c into ChrisTitusTech:main Jul 8, 2024
@og-mrk og-mrk deleted the function-improvement/installwinutilprogramwinget-2024-07-05 branch July 9, 2024 18:03
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 17, 2024
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
og-mrk added a commit to og-mrk/winutil that referenced this pull request Jul 20, 2024
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (ChrisTitusTech#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
ChrisTitusTech pushed a commit that referenced this pull request Jul 25, 2024
…ivate Function (#2396)

* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (#2271)

* Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
@ChrisTitusTech ChrisTitusTech added the skip-changelog Skip Change Logs label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog Skip Change Logs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Winutil (Issues when installing)
3 participants