Restored from previous forum. Originally posted by PB.
What is the best way to branch to another section of code from within a procedure?
You can't use Gosub to leave the procedure, and if the section you're going to
has procedure declarations, then you get an error about not having procedures
inside each other. Is there a way to do it? Thanks...
Or, how about this: do you need to use FakeReturn when using Goto to jump out
of a procedure?
PB - Registered PureBasic Coder
Edited by - PB on 19 June 2002 13:27:41
Branching to another section from a procedure
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Hi PB,
I can show you what I use:
or if you don't like Global Variables:
Don't forget to enable inline ASM.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Hi PB,
I can show you what I use:
Code: Select all
Global Value.s
Procedure TestBranch()
Value = "This is a Value from the first Procedure!"
MessageRequester("You are going to the ProcedureBranch...",Value,0)
GotoLabel.l = ?ProcedureBranch
CALL GotoLabel
MessageRequester("Congratulations, you are back!",Value,0)
EndProcedure
Procedure NewProcedure()
MessageRequester("Congratulations you are in the second Procedure!",Value,0)
EndProcedure
TestBranch()
End
ProcedureBranch:
MessageRequester("This is the ProcedureBranch!",Value,0)
NewProcedure()
Return
Code: Select all
Procedure TestBranch()
Dim Value.s(0)
Value(0) = "This is a Value from the first Procedure!"
MessageRequester("You are going to the ProcedureBranch...",Value(0),0)
GotoLabel.l = ?ProcedureBranch
CALL GotoLabel
MessageRequester("Congratulations, you are back!",Value(0),0)
EndProcedure
Procedure NewProcedure()
MessageRequester("Congratulations you are in the second Procedure!",Value(0),0)
EndProcedure
TestBranch()
End
ProcedureBranch:
MessageRequester("This is the ProcedureBranch!",Value(0),0)
NewProcedure()
Return
Don't forget to enable inline ASM.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
Thanks for your answer, Franco, but I'm not jumping to another procedure from
the calling procedure, but rather just to a label of code. Is there anything
wrong (crash-wise) about doing something like this:
PB - Registered PureBasic Coder
Thanks for your answer, Franco, but I'm not jumping to another procedure from
the calling procedure, but rather just to a label of code. Is there anything
wrong (crash-wise) about doing something like this:
Code: Select all
Procedure Commmand1_Click()
Goto NewRoutine
EndProcedure
;
End
;
NewRoutine:
a=a+1
End
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
It seems to work, but only if you don't jump back with Return like:
This code crashes on Win98 and WinXP!
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
It seems to work, but only if you don't jump back with Return like:
Code: Select all
Procedure Commmand1_Click()
Goto NewRoutine
;do something else...
;bla, bla, bla...
EndProcedure
;
Commmand1_Click()
;
End
;
NewRoutine:
a=a+1
Return
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
So inline ASM is necessary if you need to return.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
But GoSub is not allowed inside Procedures...Yep, Return is only to be used with Gosub anyway. Thanks!
So inline ASM is necessary if you need to return.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
It would have been nice to have mentioned in the docs that there is no return possibility, that you are stucked where you jump...
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
So GOTO is an implementation of JMP without adding any fancy stuff.GOTO / JMP (ASM) is a NO-Return operation.
It would have been nice to have mentioned in the docs that there is no return possibility, that you are stucked where you jump...
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.