Sign in to follow this  
Followers 0
Simpel

[Solved] For (If Then Else) Next loops fail

5 posts in this topic

#1 ·  Posted (edited)

Hello,

 

I'm searching and searching but can't find the solution. I wan't to make a for next loop like this:

 

 

$p = 0

For $n = 1 To 5

MsgBox(4096, "", $p)

If $p = 0 Then MsgBox(4096, "", "IF")

$p = 1

Else MsgBox(4096, "", "ELSE")

$p = 0

EndIf

Next

 

AU3Check means

in line 2 REF: missing Next

in line 6 ERROR: missing next / ERROR: syntax error

 

Is there no way to have a "If Then Else" loop inside a "For Next" loop?

 

Regards, Simpel

Edited by Simpel
solved

SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you put an action on the end of an If/Then statement it terminates the If/Then statement, making it a single-line If/Then and any following Else or EndIf is not treated as part of that If/Then statement.

Just move the Msgbox() down to a separate line beneath the If/Then, leaving the If/then statement ending with the word "Then"

Edit: PS - Welcome to the forum!

Edited by Spiff59

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, Simpel, welcome to the forum. You need to fix your If/Then lines. Take a look at this to see the difference.:

$p = 0

For $n = 1 To 5
MsgBox(4096, "", $p)
If $p = 0 Then
MsgBox(4096, "", "IF")
$p = 1
Else
MsgBox(4096, "", "ELSE")
$p = 0
EndIf
Next

Edit: Man I am slow today :)

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

It's just as simpel as that.

Thanks for the very fast help.

Regards, Simpel


SciTE = 3.6.2.0/full   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE   H:\...\AutoIt3   H:\...\AutoIt3\Include   H: = Network Drive

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites

Glad to be of help :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0