Jump to content

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


Recommended Posts

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
SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • Moderators

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

It's just as simpel as that.

Thanks for the very fast help.

Regards, Simpel

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...