# array of mixed numbers want to list those that are sequential

## Recommended Posts

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?

```#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 by Jury

##### Share on other sites

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 by Jury

##### Share on other sites

Jury,

Try it like this

```#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

##### Share on other sites

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

##### Share on other sites

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 by Jury

## Create an account

Register a new account