Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:41 26 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Exiting Nested "FOR . . . NEXT"  loops

     Page 3 of 3    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8578
Posted: 03:09pm 08 Oct 2022
Copy link to clipboard 
Print this post

  Quote  In MMBASIC I can't get a function to exit in the same manner,

Print fred()
Function fred()
Do
 i=i+1
 If i=50 Then
   fred=i
   Exit Function
 EndIf
 Loop Until i=1000
End Function
 
Nimue

Guru

Joined: 06/08/2020
Location: United Kingdom
Posts: 367
Posted: 03:12pm 08 Oct 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote  In MMBASIC I can't get a function to exit in the same manner,

Print fred()
Function fred()
Do
 i=i+1
 If i=50 Then
   fred=i
   Exit Function
 EndIf
 Loop Until i=1000
End Function


I think what I was doing was forgetting to set the value of the function in the function -- the below now works.  Thank you.

function check_pwd()
for x = 1 to 1000
 for y = 1 to 1000
   for z = 1 to 1000
     if x*y*z = 1500 then
     print x,y,z
     check_pwd=1500
     exit function
   end if
   next z
 next y
next x
end function


print check_pwd()



Entropy is not what it used to be
 
     Page 3 of 3    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024