I'm looking at some code examples on powershellpro.com and don't understand why he wrote sample code that loops through an array by:
...having an increment start at zero then increase by one until it is less than or equal to the length of an array minus one...
for ($i=0; $i -le $total-1; $i++)
...instead of having the increment start at zero then increase by one until it is less than the length of the array...
for ($i=0; $i -lt $total; $i++)
Am I missing something? They are functionally equivalent and will both loop through each item in the array. Personally I think the second version is cleaner. Is there a best practice or something that says you should use the first one?
>> Am I missing something?
No
>> Is there a best practice or something that says you should use the first one?
usage of 'for' cycle in powershell is the same like in any other language. just depends on attitude of the programmer which style he uses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With