Jump to content
Sign in to follow this  
BlueScreen

How To Continue A 'for' Loop From A Function

Recommended Posts

BlueScreen

Beware! This is going to be a stupid one. :whistle:

For $Iteration=1 to 5
proc1 ()
proc2 ()
proc3 ()
proc4 ()
Next
exit

func proc1 ()
msgbox (0,"","1")
endfunc

func proc2 ()
;some code here
;WHAT TO PUT HERE IN ORDER TO CONTINUE TO THE NEXT 'FOR' ITERATION FROM THIS FUNCTION??
endfunc

func proc3 ()
msgbox (0,"","3")
endfunc

func proc4 ()
msgbox (0,"","4")
endfunc

Share this post


Link to post
Share on other sites
Jos

For $Iteration=1 to 5
   proc1 ()
   if proc2 () = 1 then
      proc3 ()
      proc4 ()
   endif
Next
exit

func proc1 ()
   msgbox (0,"","1")
endfunc

func proc2 ()
  ;some code here
  ;WHAT TO PUT HERE IN ORDER TO CONTINUE TO THE NEXT 'FOR' ITERATION FROM THIS FUNCTION??
   if "...this is true then loop..."  then
      return(0)
   else
      return(1)
   endif
endfunc

func proc3 ()
   msgbox (0,"","3")
endfunc

func proc4 ()
   msgbox (0,"","4")
endfunc


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
BlueScreen

OK. 10x JdeB.

I thought about that but this means that if I want to check every function, I'll have to put lots of "IF".

If I understand correctly, there is not an other way to do it, right from the function, right?

Share this post


Link to post
Share on other sites
Jos

is this what you would like to do ??

For $Iteration=1 to 5
   $t = 0
   proc1 ()
   if $t = 0 then proc2 ()
   if $t = 0 then proc3 ()
   if $t = 0 then proc4 ()
Next
exit

func proc1 ()
   if "...this is true then loop..."  then $t=1
   msgbox (0,"","1")
endfunc

func proc2 ()
  ;some code here
  ;WHAT TO PUT HERE IN ORDER TO CONTINUE TO THE NEXT 'FOR' ITERATION FROM THIS FUNCTION??
   if "...this is true then loop..."  then $t=1
endfunc

func proc3 ()
   if "...this is true then loop..."  then $t=1
   msgbox (0,"","3")
endfunc

func proc4 ()
   msgbox (0,"","4")
endfunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
BlueScreen

Yep. This is it. The issue is that in AutoIt 91 (and greather), it is no more (but justified) possible to use NEXT from a function in order to continue a for Loop, so I thought there is a new command that can do it (in order to avoid all the "IF".

10x JdeB. I'll use your suggestion.

Share this post


Link to post
Share on other sites
Jos

jon added more syntax checking in 3.0.88 .. one of them was:

- Changed: All block structures (IF/WHILE/FOR, etc.) are now checked before execution.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
CyberSlug

JdeB, in your second example, does $t need to be declared as a Global variable?

Here's another (but related) idea that depends on the return values of each proc:

For $Iteration=1 to 5
  proc1 ()
  If proc2 () then ContinueLoop
  If proc3 () then ContinueLoop
  If proc4 () then ContinueLoop
Next

Edit: fixed code /code tags

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Jos

CyberClug,

When a Variable is used before calling the Function it is know at the function level so guess can be considered Global.

try the below script...

Forgot about the ContinueLoop :whistle: ... agree that its better to use it as you show and use the Return(1) in stead of $t=1 in the function.

For $Iteration=1 to 4
  $t = 0
  proc1 ()
  if $t = 0 then proc2 ()
  if $t = 0 then proc3 ()
  if $t = 0 then proc4 ()
Next
exit

func proc1 ()
  if $Iteration = 1  then $t=1
  msgbox (0,"","1")
endfunc

func proc2 ()
  if $Iteration = 2  then $t=1
  msgbox (0,"","2")
endfunc

func proc3 ()
  if $Iteration = 3  then $t=1
  msgbox (0,"","3")
endfunc

func proc4 ()
  msgbox (0,"","4")
endfunc
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Valik

Doesn't ContinueLoop restart the loop from the top, thus none of the code below will be executed? I can't remember, I haven't used it in awhile, but I thought it was the same as C's contine keyword which restarts the loop again.

Share this post


Link to post
Share on other sites
CyberSlug

Doesn't ContinueLoop restart the loop from the top, thus none of the code below will be executed?  I can't remember, I haven't used it in awhile, but I thought it was the same as C's contine keyword which restarts the loop again.

From the help file:
;Print all numbers from 1 to 10 except number 7
For $i = 1 to 10
    If $i = 7 Then ContinueLoop
    MsgBox(0, "The value of $i is:", $i)
Next

I think that is what BlueScreen wants.... Try it out after you get your computer working!

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites
Valik

Thanks CyberSlug, I see that I was correct on what ContinueLoop did (Yay for my memory working for once), but was incorrect on what was trying to be achieved. I just went back and re-read some of the posts and see that I interpreted the goal wrong. Now that I've taken a second look, I also think that is what he wanted to do. It threw me off slightly seeing so many "If function Then ContinueLoop" statements in a row.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.