Jump to content

BitByteBit

Active Members
  • Posts

    129
  • Joined

  • Last visited

Reputation Activity

  1. Like
    BitByteBit reacted to BrewManNH in Is using Ubound in For To Next declarations loops bad practice   
    Wouldn't the third example above be practically the same as the example above using $a = UBound($array) - 1? Again, in testing I don't see any speed difference in doing it in any of the 3 methods, they're all statistically the same in repeated tests.
  2. Like
    BitByteBit reacted to guinness in Is using Ubound in For To Next declarations loops bad practice   
    It's nothing to do with speed, just ease of readability and the unnecessary use of calling a secondary function for information you already know.
  3. Like
    BitByteBit reacted to guinness in Is using Ubound in For To Next declarations loops bad practice   
    Also for the sake of learning (I presume this is what you want?) your example is declaring the variable in Global scope when it should be Local.


    Local $aProblems[99] ; Jay-Z Array For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next This is valid use, as the variable is use other than its current scope.

    Global $aProblems[99] ; Jay-Z Array For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next Func SomeFunc() For $i = 0 To UBound($aProblems) - 1 ; Enumerate through the array. Next EndFunc ;==>SomeFunc Func AnotherFunc() $aProblems = 0 EndFunc ;==>AnotherFunc
    Local $aProblems[99] = [98] ; Jay-Z Array For $i = 1 To $aProblems[0] ; If I know the size of the array beforehand, I like to use the 0th index as the count. ; This theory can also be applied to arrays which are dynamic too. ; Enumerate through the array. Next
  4. Like
    BitByteBit reacted to Melba23 in Is using Ubound in For To Next declarations loops bad practice   
    BitByteBit,

    guinness is correct - in your first example, the loop bound is only evaluated once: as you enter the loop. You can modify the loop counter programatically by changing the value of $i inside the loop, but changing the size of the array within the loop will not affect the intially set limit. That is why when you are changing the size of the array (deleting unnecessary elements for example) you must always start at the bottom of the array and work up using Step -1.

    M23
  5. Like
    BitByteBit got a reaction from dickjones007 in delete duplicate lines from text file or array   
    This should do the trick. You will however loose the order of your links, is that a problem?


    #include<array.au3> #include<file.au3> Dim $aFile _FileReadToArray(@DesktopDir & '\Codes2.txt', $aFile) _ArrayDelete($aFile, 0) _ArraySort($aFile) For $i = UBound($aFile) - 1 To 1 Step -1 If $aFile[$i] = $aFile[$i - 1] Then _ArrayDelete($aFile, $i) Next _ArrayDisplay($aFile)
×
×
  • Create New...