Jury Posted August 22, 2013 Share Posted August 22, 2013 (edited) Why does this stop at 16? If the conditional If statement isn't satisfied wouldn't the loop carry on? Perhaps there is a better way do do this? expandcollapse popup#include <Array.au3> Local $array[51] $array[0] = "1" $array[1] = "2" $array[2] = "3" $array[3] = "4" $array[4] = "5" $array[5] = "6" $array[6] = "7" $array[7] = "8" $array[8] = "9" $array[9] = "10" $array[10] = "11" $array[11] = "12" $array[12] = "13" $array[13] = "14" $array[14] = "15" $array[15] = "16" $array[16] = "15" $array[17] = "16" $array[18] = "17" $array[19] = "18" $array[20] = "19" $array[21] = "20" $array[22] = "21" $array[23] = "17" $array[24] = "18" $array[25] = "19" $array[26] = "20" $array[27] = "21" $array[28] = "22" $array[29] = "23" $array[30] = "24" $array[31] = "25" $array[32] = "26" $array[33] = "27" $array[34] = "28" $array[35] = "29" $array[36] = "30" $array[37] = "31" $array[38] = "32" $array[39] = "33" $array[40] = "34" $array[41] = "35" $array[42] = "36" $array[43] = "37" $array[44] = "38" $array[45] = "39" $array[46] = "40" $array[47] = "41" $array[48] = "42" $array[49] = "43" $array[50] = "44" $i = 0 Do If $array[$i] = $i + 1 Then ConsoleWrite($i & ' ' & $array[$i] & @CRLF) $i = $i + 1 Until $i = UBound($array) - 1 Edited August 22, 2013 by Jury Link to comment Share on other sites More sharing options...
Jury Posted August 22, 2013 Author Share Posted August 22, 2013 (edited) Oops! this is a reply to an answer that was deleted. Yes the array is mixed numbers I'd hoped that when the If condition was satisfied with the array value of 16 then it would continue to the next array index number and seeing that din't satisfy the array value 17 (because it is 15) it would continue again until the array value 17 was found. Edited August 22, 2013 by Jury Link to comment Share on other sites More sharing options...
Solution kylomas Posted August 22, 2013 Solution Share Posted August 22, 2013 Jury, Sorry about that...too early here. Try it like this expandcollapse popup#include <Array.au3> Local $array[51] $array[0] = "1" $array[1] = "2" $array[2] = "3" $array[3] = "4" $array[4] = "5" $array[5] = "6" $array[6] = "7" $array[7] = "8" $array[8] = "9" $array[9] = "10" $array[10] = "11" $array[11] = "12" $array[12] = "13" $array[13] = "14" $array[14] = "15" $array[15] = "16" $array[16] = "15" $array[17] = "16" $array[18] = "17" $array[19] = "18" $array[20] = "19" $array[21] = "20" $array[22] = "21" $array[23] = "17" $array[24] = "18" $array[25] = "19" $array[26] = "20" $array[27] = "21" $array[28] = "22" $array[29] = "23" $array[30] = "24" $array[31] = "25" $array[32] = "26" $array[33] = "27" $array[34] = "28" $array[35] = "29" $array[36] = "30" $array[37] = "31" $array[38] = "32" $array[39] = "33" $array[40] = "34" $array[41] = "35" $array[42] = "36" $array[43] = "37" $array[44] = "38" $array[45] = "39" $array[46] = "40" $array[47] = "41" $array[48] = "42" $array[49] = "43" $array[50] = "44" $i = 1 for $j = 0 to ubound($array) - 1 if $array[$j] = $i then ConsoleWrite(stringformat('%02i found at element = %02i',$i,$j) & @LF) $i += 1 EndIf next kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted August 22, 2013 Share Posted August 22, 2013 To answer your origional question: The loop does continue but this condition If $array[$i] = $i + 1 is never true again kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Jury Posted August 22, 2013 Author Share Posted August 22, 2013 (edited) Thanks kylomas looking at your code I now see my mistake in using $i as the array index and also in the conditional statment - your code will give me something to study. jury Edited August 22, 2013 by Jury 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