Exit from Procedure
Exit from Procedure
What is the equivalent to "EXIT SUB", that is, how to exit from a subroutine before reaching the EndSubroutine. The "Break" command only exit from the current loop. And "Break #" (where # is the number of the nested loop) only exit from the that number of nested loops. I prefer not to use "Goto label", even if that would solve the problem.
-
Num3
- PureBasic Expert

- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Yes!
Code: Select all
For a=1 to 100000
If a=10
Break ; exits the loop
Endif
Next
Code: Select all
Procedure DoSomething()
For a=1 to 100000
If a=10
ProcedureReturn ; exits the procedure
Endif
Next
Endprocedure
More than one ProcedureReturn
Ok, thanks.
So this mean that it's possible to have more than one (1) line with ProcedureReturn in a subroutine.
So this mean that it's possible to have more than one (1) line with ProcedureReturn in a subroutine.
-
Seymour Clufley
- Addict

- Posts: 1267
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
-
Num3
- PureBasic Expert

- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
Here's a more complex example:
Code: Select all
Procedure Morpheus(Answer.s)
If answer.s="blue pill"
ProcedureReturn 1 ; returns 1
Endif
If answer.s="red pill"
ProcedureReturn 2
Endif
;If no answer return 0
ProcedureReturn 0
Endprocedure
Debug Morpheus("blue pill")
