Jump to content

how to skip few lines of code during the run


sqa
 Share

Recommended Posts

PincoPanco,

 

It does - but it runs the code within it, not the Case comparison itself. ;)

M23

Edit: I have amended the Help file text to make this (I hope) clearer:

 

"Normally in a Select or Switch structure, the code within each Case block ends when the next Case statement is encountered. Executing ContinueCase tells AutoIt to stop executing the code within the current Case block and start executing the code within the next Case block. AutoIt does not evaluate the next Case comparison statement - only the code inside the block is run."

yes, in this way is explained more clearly.

however this ContinueCase it also seems a sort of GoTo spaghetti... :)

 

I know, this trips me up every once and a while also...

... indeed...

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Moderators

PincoPanco,

It is actually very useful - and not remotely pasta-like. :D

For example, suppose you have "Save" and "Cancel" buttons in a script where there is fair amount of tidying to do on exit. You can run the "Save" code and then immediately move straight into the clear-up code that is run when you press the "Cancel" button - it saves creating yet another function or repeating the same lines of code in both Case blocks: ;)

...
Case $cSave
    ; Save code
    ContinueCase
Case $cCancel
    ; Clear up code
    Exit
Case ....
M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

PincoPanco,

It is actually very useful - and not remotely pasta-like. :D

For example, suppose you have "Save" and "Cancel" buttons in a script where there is fair amount of tidying to do on exit. You can run the "Save" code and then immediately move straight into the clear-up code that is run when you press the "Cancel" button - it saves creating yet another function or repeating the same lines of code in both Case blocks: ;)

...
Case $cSave
    ; Save code
    ContinueCase
Case $cCancel
    ; Clear up code
    Exit
Case ....
M23

 

 

Yes, of course, everything it is useful when it is needed,

could be equally useful a new command, for example ContinueCheck,

making it possible to continue with the next  check rather than skip it

(in effect, this command does not exist).

This is just an "non sense" example to show how the ContinueCheck should flow

of course in other situations could have "more sense" and more usefullness

...
    Case $cOtherStuff
        ; OtherStuff code
        ....
        If $ToBeSaved Then
            ContinueCase ; ------------+
        Else ;                         |
            MoreStuff() ;              |
            ContinueCheck ; ----+      |
        EndIf ;                 |      |
    Case $cSave ; <-------------+      |
            ;                          |
            ; Save code ;   <----------+
            ...
            ContinueCase
    Case $cCancel
            ; Clear up code
            Exit ; ---> Go away
    Case ....

    Func MoreStuff()
        If $x Then
            $cSave = True
        Else
            $cSave = False
            $cCancel = True
        EndIf
        Return
    EndFunc   ;==>MoreStuff

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Moderators

PincoPanco,

 

making it possible to continue with the next check rather than skip it

In that case use multiple If structures so that you can check all the possibiltiies that you require - the whole point of Switch and Select structures is that only one of the Case statements can ever be actioned. ;)

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

 

Yes, of course, everything it is useful when it is needed,

could be equally useful a new command, for example ContinueCheck,

making it possible to continue with the next  check rather than skip it

(in effect, this command does not exist).

This is just an "non sense" example to show how the ContinueCheck should flow

of course in other situations could have "more sense" and more usefullness

...
    Case $cOtherStuff
        ; OtherStuff code
        ....
        If $ToBeSaved Then
            ContinueCase ; ------------+
        Else ;                         |
            MoreStuff() ;              |
            ContinueCheck ; ----+      |
        EndIf ;                 |      |
    Case $cSave ; <-------------+      |
            ;                          |
            ; Save code ;   <----------+
            ...
            ContinueCase
    Case $cCancel
            ; Clear up code
            Exit ; ---> Go away
    Case ....

    Func MoreStuff()
        If $x Then
            $cSave = True
        Else
            $cSave = False
            $cCancel = True
        EndIf
        Return
    EndFunc   ;==>MoreStuff

 

Do you mean this?

    ...
    Case $cOtherStuff
        ; OtherStuff code
        ....
        If Not $ToBeSaved Then MoreStuff()

        ContinueCase ; ------------+   |
    Case $cSave ;                      |
            ;                          |
            ; Save code ;   <----------+
            ...
            ContinueCase
    Case $cCancel
            ; Clear up code
            Exit ; ---> Go away
    Case ....

;

Or do you mean something like this?

...
    Case $cOtherStuff
        ; OtherStuff code
        ....
        $cSave = True
        If Not $ToBeSaved Then MoreStuff()
        
        If $cSave Then ContinueCase
    Case $cSave 
            ; Save code
            ...
            ContinueCase
    Case $cCancel
            ; Clear up code
            Exit ; ---> Go away
    Case ....
Edited by czardas
Link to comment
Share on other sites

PincoPanco,

 

.....  the whole point of Switch and Select structures is that only one of the Case statements can ever be actioned. ;)

M23

 

... the ContinueCase statement breaks this rule, isn't it?

in the same way the "ContinueCheck" statement could be allowed :)

 

Do you mean?

    ...
    Case $cOtherStuff
        ; OtherStuff code
        ....
        If Not $ToBeSaved Then MoreStuff()

        ContinueCase ; ------------+   |
    Case $cSave ;                      |
            ;                          |
            ; Save code ;   <----------+
            ...
            ContinueCase
    Case $cCancel
            ; Clear up code
            Exit ; ---> Go away
    Case ....

not exactly,

in short, I wish I could make the control of the $cSave variable  (with Case $cSave) when returning from function instead of "jumping" forward

Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • Moderators

PincoPanco,

No, I do not believe that ContinueCase breaks the rule that only one Case can be actioned. The whole point of ContinueCase is that you can run code when the relevant Case is not actioned because its condition is not met - as in the "Save"/"Cancel" example I suggested earlier. :)

This looks to be the functional equivalent of the pseudo ContinueCheck code you posted earlier:

#include <Constants.au3>

; Dummies
Global $cSave, $cCancel

; Flags to tell us whether to save and/or cancel
Global $fSave = True, $fCancel = False

; Fire just the single case
$cControl = 1

Switch $cControl
    Case 1
        ; Run the code and set the save flag if required
        OtherStuff()
        ; If the flag was not set then try again
        If Not $fSave Then
            ; Run this code and perhaps set Save and Cancel flags
            MoreStuff()
        EndIf
        ; Now continue case in any event
        ContinueCase
    Case $cSave
        MsgBox($MB_SYSTEMMODAL, "Hi", "In Save Case")
        ; Check the flag = note the default is True so it will fire if actioned directly
        If $fSave Then
            ; Save code
            MsgBox($MB_SYSTEMMODAL, "Hi", "Running Save Code")
        EndIf
        ; Now continue case if required - note it will not default to this, only if the flag is set
        If $fCancel Then
            ContinueCase
        EndIf
    Case $cCancel
        ; Note this will always fire if actioned directly
        MsgBox($MB_SYSTEMMODAL, "Hi", "In Cancel Case")
        ; Clear up code
        MsgBox($MB_SYSTEMMODAL, "Hi", "Running Cancel Code")
        Exit
EndSwitch

Func OtherStuff()
    If Random(0, 1, 1) Then
        ConsoleWrite("Saving" & @CRLF)
        $fSave = True
    Else
        $fSave = False
    EndIf
EndFunc

Func MoreStuff()
    If Random(0, 1, 1) Then
        ConsoleWrite("Saving" & @CRLF)
        $fSave = True
    Else
        $fSave = False
    EndIf
    If Random(0, 1, 1) Then
        ConsoleWrite("Cancelling" & @CRLF)
        $fCancel = True
    Else
        $fCancel = False
    EndIf
EndFunc   ;==>MoreStuff
And now I have wasted enough time on this pointless discussion and so... :bye:

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

PincoPanco - I didn't read the whole thread, but I'm quite sure the answers here are not a waste of time. I just think Melba23 has a lot on his hands, and I'm also grateful for the contributions he makes.

GoTo is not evil - it's just somewhat antiquated. To be honest I never thought of using Switch statements to mimic this outdated behaviour. It has some curiousity value, but nothing much beyond that. :)

;

Global $iPosition = 1, $sOutput = ""

While 1
    Switch $iPosition
        Case 1
            $sOutput &= "h"

        Case 2
            $sOutput &= "e"

        Case 3
            $sOutput &= "l"
            $sLen = StringLen($sOutput)
            If $sLen = 3 Then _GoTo(3)
            If $sLen = 10 Then _GoTo(8)

        Case 4
            $sOutput &= "o"
            If StringLen($sOutput) = 5 Then ContinueCase
            _GoTo(7)

        Case 5
            $sOutput &= " "
            ContinueCase

        Case 6
            $sOutput &= "w"
            _GoTo(4)

        Case 7
            $sOutput &= "r"
            _GoTo(3)

        Case 8
            $sOutput &= "d"
            ExitLoop ; finished
    EndSwitch

    $iPosition += 1
WEnd

MsgBox(0, "", $sOutput)

Func _GoTo($i)
    $iPosition = $i -1
EndFunc

;

Not quite as efficient as the first AutoIt tutorial. :D

Link to comment
Share on other sites

I thought it was an interesting exercise. It gives me an impression of how much things have changed over time. There were no real opportunities to study programming when I was in school, but I vaguely remember something about flowcharts in maths. I think every method has its place. I'm not sure where I might use a construct like this, but you never know - it is after all quite easy to follow, if not also a little crazy. :tv_happy:

Edited by czardas
Link to comment
Share on other sites

Everyone reading the part of this thread about Goto and/or posting about it would gain considerable benefit reading Structured Programming with go to statements --a 1974 paper by Donald Knuth (again)-- if they haven't yet.

Interestingly enough, this opinion fits nicely with the current news in that it's an early transpose of Mandela's "let's learn to live together in peace".

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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