Zomp Posted September 4, 2008 Share Posted September 4, 2008 (edited) Suppose I have $Array1[1000] and $Array2[1000] Which is the fastest and simplest way to check if they (i.e. all their elements) are equal? Have I to write $equal=true for $i=0 to 999 if not $Array1[$i]=$Array2[$i] then $equal=false exitloop endif next consolewrite($equal @LF) or is there something better? Edited September 4, 2008 by Zomp Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 4, 2008 Share Posted September 4, 2008 As far as I know, you have to compare elements individually. Link to comment Share on other sites More sharing options...
DarkwarlorD Posted September 4, 2008 Share Posted September 4, 2008 (edited) I believe that a small correction help you:$equal=true for $i=0 to 999 if not $Array1[$i]=$Array2[$i] then $equal=false exitloop endif next consolewrite($equal @LF)Try This:$equal=true for $i=0 to 999 if not $Array1[$i]=$Array2[$i] then $equal=false exitloop endif consolewrite("Element " & $i & ": " & $equal & @CRLF) next Edited September 4, 2008 by DarkwarlorD Link to comment Share on other sites More sharing options...
Pain Posted September 4, 2008 Share Posted September 4, 2008 (edited) Try something like this, to be honest I've never used For...In loops before until today so I'm not sure it will work. Local $i = 0 FOR $element IN $aArray If $test = $element Then Return 0 $i = $i + 1 NEXT Return 1 Edit: typo Edited September 4, 2008 by Pain Link to comment Share on other sites More sharing options...
Richard Robertson Posted September 4, 2008 Share Posted September 4, 2008 That code you posted is incorrect. You ended up with two Nexts and I have no idea what that Return is doing for you. Link to comment Share on other sites More sharing options...
Pain Posted September 4, 2008 Share Posted September 4, 2008 (edited) Sorry, I removed one of the Nexts. What I posted is a part (a function) of one of my scripts where I compare the elements in a array and Return true or false if there was any duplicated elements. As I said, I'm not sure it will work. nvm I just noticed my function only found duplicated element in same array and not in two. anyways here is a example of the function I'm using in my script Dim $Array[5] = [1,2,3,4,5] Global $test = 1;6 compare() Func compare() Local $i = 0 For $element in $Array If $test = $element Then MsgBox (0,"","Duplicated element!") $i = $i + 1 Next EndFunc Edited September 4, 2008 by Pain Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now