# If Loop Errors

## Recommended Posts

I'm trying to do a loop based on a condition without forming 2 totally seporate loop statements, so this is what I did:

```For
If \$Formating = 1 Then
\$a = 1 To \$looping - 1
Else
\$a = 1 To \$looping
EndIf```

I'm getting an error with this. I've tried various combonations surrounding this small statement, but all of them produce errors. Is something like this possible, or do I need to do two entire loop functions?

##### Share on other sites

I'm trying to do a loop based on a condition without forming 2 totally seporate loop statements, so this is what I did:

```For
If \$Formating = 1 Then
\$a = 1 To \$looping - 1
Else
\$a = 1 To \$looping
EndIf```

I'm getting an error with this. I've tried various combonations surrounding this small statement, but all of them produce errors. Is something like this possible, or do I need to do two entire loop functions?

why not just:

```If \$formatting = 1 Then
\$step = -1
Else
\$step = 1
EndIf
For \$a = 1 To \$looping Step \$step```

***edit*** apparently changed [ autoit] [ /autoit] tags to [ code] [ /code] tags, since the former didn't work for me...

##### Share on other sites

Thanks, but that doesn't work...or at least the way I need or expect it to work.

\$looping is a variable input box that determines how many times the looping is suppose to function.

If \$Formatting = 1 then I want \$looping to happen one less times. If \$Formatting does not equal one, then the \$looping happens to whatever number specified in the input.

With what you gave me, if it equals 1, which would be "-1", the loop just happens once...meaning it doesn't loop. And the Else, will make it just continue none stop.

What now?

##### Share on other sites

```For \$a = 1 To \$looping - \$Formatting
...
Next```

only works if \$formatting is 0 or 1

else you could do like

```if \$formatting Then
For \$a = 1 To \$looping - 1
_function()
next
else
for \$a = 1 to \$looping
_function()
Next
Endif

func _function()
...
endfunc```

typed in the brouwser so dont hang me...

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

##### Share on other sites

The second one is what I was trying to avoid because it would make the script too big. The first one was causing problems.

What I did was take the idea of the first one and added something to it. I made a checkbox activate a hidden inputbox with a 1 or 0, and had the "Formatting" read that inputbox. That worked.

## Create an account

Register a new account

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...