Jump to content

Switch between while loops?


 Share

Recommended Posts

Hi Folks,

Ive got my script working and all is well, however they only work individually so basically comment out the other functions(run 1 at a time).

E.G. When Test_Assert is run @error=1 and then it exitloops.

Here I want it to go into the Test_ExceptionWindow() loop and then have that go into the Test_Abnormal() loop.

Ive tired continueloop etc but cant seem to get it out.

While 1

        If Test_Assert() Then
            If @error = 1 Then ExitLoop
        Else
            If @error = 0 then Return 0
        EndIf

        WEnd

        While 1

        If Test_ExceptionWindow() Then
            If @error = 0 Then ExitLoop
        EndIf

        WEnd

        While 1

        If Test_Abnormal() Then
            If @error = 1 Then ExitLoop
        Else
            If @error = 0 then Return 0
        EndIf

        WEnd
Link to comment
Share on other sites

Why not all in one loop with one status variable?

If $status = 1 Then funcA()

If $status = 2 Then funcB()

If $status = 3 Then funcC()

In the functions you set the status.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Why not all in one loop with one status variable?

If $status = 1 Then funcA()

If $status = 2 Then funcB()

If $status = 3 Then funcC()

In the functions you set the status.

I see what you mean. So instead of having return 0 and 1. Have like return 0,1,2,3,4 etc?

Link to comment
Share on other sites

My thought was, you ve got a function which should be executed untill somthing happens. If that magic thing happens you set the global status variable to the next level.

After the functions has finished your script is back in that loop. Then the status is checked and the next step/function is executed.

That is all.

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Somthing like this

#include <Date.au3>
Global $status = 0

While 1
    Switch $status
        Case 0
            ConsoleWrite('The start : ' & _NowCalc() & @CRLF)
            $status = 1
        Case 1
            funcA()
        Case 2
            ConsoleWrite('The END' & @CRLF)
            Exit (0)
    EndSwitch
    Sleep(500)
WEnd

Func funcA()
    Do
        ConsoleWrite(@SEC & @CRLF)
        Sleep(1000)
    Until @SEC >= 30
    $status = 2
EndFunc   ;==>funcA

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

 

Somthing like this

#include <Date.au3>
Global $status = 0

While 1
    Switch $status
        Case 0
            ConsoleWrite('The start : ' & _NowCalc() & @CRLF)
            $status = 1
        Case 1
            funcA()
        Case 2
            ConsoleWrite('The END' & @CRLF)
            Exit (0)
    EndSwitch
    Sleep(500)
WEnd

Func funcA()
    Do
        ConsoleWrite(@SEC & @CRLF)
        Sleep(1000)
    Until @SEC >= 30
    $status = 2
EndFunc   ;==>funcA

ok so im just trying to get my head around it.

In case 0 when $status=1 does that then go to case 1?

Link to comment
Share on other sites

No, if you want to link the Case 0 to the Case 1, you need to add a ContinueCase to the end of the Case 0.

The code given by Xenobiologist is an example, are you sure that it fits your needs?

Br, FireFox.

Link to comment
Share on other sites

No, if you want to link the Case 0 to the Case 1, you need to add a ContinueCase to the end of the Case 0.

The code given by Xenobiologist is an example, are you sure that it fits your needs?

Br, FireFox.

Im trying to see if it can. Basically want to run through each function in the script. Even if one function runs correctly and exits(outputs a messagebox or something) I still want the script to continue to run the other two functions. Rather than stop after the first execution of the first function....if that makes sense?

Link to comment
Share on other sites

Then I would say the same as in the reply #2.

With an advanced example :

Local $iStatus = 0

While 1
    If $iStatus = 0 Then
        _MyFuncA()
        If @error = 1 Then ExitLoop
        If @error = 0 Then $iStatus = 1 ;go to next func
    ElseIf $iStauts = 1 Then
        _MyFuncB()
        If @error = 1 Then ExitLoop
        If @error = 0 Then $iStatus = 2 ;go to next func (not written here)
    EndIf
    ;etc
WEnd
Edit: Added indents.

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

I'm thinking the OP could be a bit more clear.

Are you wanting to continue to the next check regardless if the previous passes or fails?

Yea thats what I wanna do.

If it passes or fails doesnt matter....check the next function etc

Link to comment
Share on other sites

If @error = 1 Then
    $iStatus = 2
    ExitLoop
EndIf

But I don't understand the purpose of updating the variable because all the script is in the loop, or you have something after which uses this variable ?

Br, FireFox.

updating $status? I thought updating that and placing it into another function would allow me to use that other function? Or at least thats what I gather from the replies so far.

Link to comment
Share on other sites

Yea thats what I wanna do.

If it passes or fails doesnt matter....check the next function etc

Anything wrong with keeping it super simple then?

If Test_Assert() Then
    $Test1 = 1
Else
    $Test1 = 0
EndIf

If Test_ExceptionWindow() Then
    $Test2 = 1
Else
    $Test2 = 0
EndIf

If Test_Abnormal() Then
    $Test3 = 1
Else
    $Test3 = 0
EndIf

Or if each must be in a loop:

While 1
    If Test_Assert() Then
        $Test1 = 1
        ExitLoop
    Else
        $Test1 = 0
        ExitLoop
    EndIf
WEnd

While 1
    If Test_ExceptionWindow() Then
        $Test2 = 1
        ExitLoop
    Else
        $Test2 = 0
        ExitLoop
    EndIf
WEnd

While 1
    If Test_Abnormal() Then
        $Test3 = 1
        ExitLoop
    Else
        $Test3 = 0
        ExitLoop
    EndIf
WEnd
Edited by danwilli
Link to comment
Share on other sites

updating $status? I thought updating that and placing it into another function would allow me to use that other function? Or at least thats what I gather from the replies so far.

Because that's what we understood.

Link to comment
Share on other sites

If it doesn't matter what happens inside your functions then you needn't to react on the return value at all.

I don't get it :

$count = 1

While 1
    ConsoleWrite('!Run : ' & $count & @CRLF)
    _a()
    _b()
    _c()
    $count += 1
WEnd

Func _a()
    ConsoleWrite('a' & @CRLF)
    Sleep(500)
EndFunc   ;==>_a
Func _b()
    ConsoleWrite('b' & @CRLF)
    Sleep(500)
EndFunc   ;==>_b
Func _c()
    ConsoleWrite('c' & @CRLF)
    Sleep(500)
EndFunc   ;==>_c

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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...