Jump to content
Macro Express Forums

Handy Trick- An Artificial "next Iteration"


Linda
 Share

Recommended Posts

Hi!

 

If someone already has a more elegant solution for this, or if I've missed a built-in feature, please let me know :).

 

I had been somewhat irritated by the lack of a "next iteration" function for the ME repeat loops (at least in 3.0.4.1) -- functionality that would let you skip the rest of this iteration of the loop, and begin the next iteration. I've been spoiled by it in other languages.

 

But, behold! It is possible to do this in ME! :D

 

Immediately inside your Repeat loop, create a second, inner repeat loop that simply says "Repeat 1 Times". Now, using "Repeat Exit" will jump you out of the inner repeat loop- and back to the beginning of the next iteration of the outer loop!

 

To be able to also really "Repeat Exit" the outer loop from the inner one, you can define a "Really Exit?" variable, and have code at the bottom of the outer loop check this and "Repeat Exit" if it = 1 or "true" or whatever.

 

Posting this in hopes that someone else will also find it useful. ;)

Link to comment
Share on other sites

Sorry, I guess I wasn't very clear, was I?

 

Is this better:

 

// T1 = Break all the way out of loop? (True/False)
Variable Set String %T1% "False"
//
// Any type of "Repeat" or file-reading loop
//      will work for the outer repeat loop
Repeat with Variable using %N2%
    Repeat Start (Repeat 1 times)
         If <some condition>
               // Do some processing
               // now we want to go to the next iteration 
               //     of the %N2% loop
               Repeat Exit
         end if 
         
         // Do some other processing

         if <some other condition>
              // Do some processing
              // now we want to exit the repeat loop entirely
              Variable Set String %T1% "True"
              Repeat Exit
         end if
         if <yada yada yada>
              // Process, process, process
              // Next iteration:
              Repeat Exit
         end if

         // do some processing

         if <etc>
             // ...
         end if
    Repeat End
    //
    if Variable %T1% = "True"
          Repeat Exit
    end if
Repeat End

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...