sfresher Posted September 26, 2008 Share Posted September 26, 2008 I was trying to write a complex FOR loop, like this: For a 2D array, from 1st to last column, but skip for item array[1][n] if the value is "NA". For ($n = 1 to $array[0][1]) & ($array[1][n] <> "NA") I got a compling error: missing seperater character after keyword. Note: array is a 2D array, so $array[0][1] returns its number of max columns. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 26, 2008 Moderators Share Posted September 26, 2008 I was trying to write a complex FOR loop, like this: For a 2D array, from 1st to last column, but skip for item array[1][n] if the value is "NA". For ($n = 1 to $array[0][1]) & ($array[1][n] <> "NA") I got a compling error: missing seperater character after keyword. Note: array is a 2D array, so $array[0][1] returns its number of max columns.Provide a real example. What you posted is no where near what the help file shows how to do a For/Next loop. Parameters variable The variable used for the count. start The initial numeric value of the variable. stop The final numeric value of the variable. stepval [optional] The numeric value (possibly fractional) that the count is increased by each loop. Default is 1.Note those parameters require an integer value. Also note, that variables here are declared with $ (dollar signs), and please understand, it's unlike C anything where you nest the statement on one line. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ame1011 Posted September 26, 2008 Share Posted September 26, 2008 (edited) try: For $n = 1 to $array[0][1] if $array[1][$n] = "NA" then ContinueLoop ;rest of code here Next Edited September 26, 2008 by ame1011 [font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font] Link to comment Share on other sites More sharing options...
sfresher Posted September 26, 2008 Author Share Posted September 26, 2008 (edited) I came with an easier way to describle my problem: Let's say the array is $array = [true, true, false, true, true] For $n = 1 to 5 If $array[$n] = true, continue the loop. If all values are true, skip the next step. If $array[$n] = false, exist the loop immediately. Go to next step. Edited September 26, 2008 by sfresher Link to comment Share on other sites More sharing options...
Developers Jos Posted September 26, 2008 Developers Share Posted September 26, 2008 Something like this? Dim $array[5] = [True, True, False, True, True] For $n = 0 To 4 If $array[$n] = False Then ExitLoop Next If $n = 5 Then ; All are True Exit Else MsgBox(262144,'test',"At least one is False") EndIf SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
martin Posted September 26, 2008 Share Posted September 26, 2008 Something like this? Dim $array[5] = [True, True, False, True, True] For $n = 0 To 4 If $array[$n] = False Then ExitLoop Next If $n = 5 Then ; All are True Exit Else MsgBox(262144,'test',"At least one is False") EndIfWell it works, but I'm sure my Grandmother told me never to use a loop variable outside of the loop. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Developers Jos Posted September 27, 2008 Developers Share Posted September 27, 2008 Well it works, but I'm sure my Grandmother told me never to use a loop variable outside of the loop.I never had that "Grandmother" training, but why would that be an issue? (I am not really a programmer in real life so that could be the reason too I have never heard it )I thought it was quit common that the loop variable is set to the last used value in the loop and when the for-next loop went "all the way" its set to the max value +1.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ssubirias3 Posted September 27, 2008 Share Posted September 27, 2008 I came with an easier way to describle my problem: Let's say the array is $array = [true, true, false, true, true] For $n = 1 to 5 If $array[$n] = true, continue the loop. If all values are true, skip the next step. If $array[$n] = false, exist the loop immediately. Go to next step.Another example based on Jos' code. Dim $array[5] = [True, True, False, True, True], $cTrue For $n = 0 To UBound($array, 1) - 1 If $array[$n] == False Then ExitLoop ElseIf $array[$n] == True Then $cTrue = $cTrue + 1 ; more steps go here EndIf Next MsgBox(262144, 'test', "Counted " & $cTrue & ' "True" before "False" was encountered.') 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