Return more conventional
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Manolo.
Hi Fred,
I think that Return will be more conventional with others Basic's:
Actual situation:
If a = 10
FakeReturn
Goto Main_Loop
Endif
Return
Conventional Return:
If a = 10
Return Main_Loop
Endif
Return
The FakeReturn in this case not is necesary (And in all cases).
Regards,
Manolo
Hi Fred,
I think that Return will be more conventional with others Basic's:
Actual situation:
If a = 10
FakeReturn
Goto Main_Loop
Endif
Return
Conventional Return:
If a = 10
Return Main_Loop
Endif
Return
The FakeReturn in this case not is necesary (And in all cases).
Regards,
Manolo
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Amiga5k.
If you ask me, exiting out of a subroutine with Goto is bad programming and should be strongly discouraged because errors can occur that are very hard to pin down. The example in the help file is a big no-no, imho:
Gosub SubRoutine1
SubRoutine1:
...
If a = 10
FakeReturn
Goto Main_Loop
Endif
Return
Although modern structured languages, such as Purebasic, can do without Goto altoghether, if you must use goto, only use it WITHIN the subroutine.
Take care,
Russell Jones
***I snatch kisses!***
If you ask me, exiting out of a subroutine with Goto is bad programming and should be strongly discouraged because errors can occur that are very hard to pin down. The example in the help file is a big no-no, imho:
Gosub SubRoutine1
SubRoutine1:
...
If a = 10
FakeReturn
Goto Main_Loop
Endif
Return
Although modern structured languages, such as Purebasic, can do without Goto altoghether, if you must use goto, only use it WITHIN the subroutine.
Take care,
Russell Jones
***I snatch kisses!***
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Amiga5k.
So my question is: Why is FakeReturn even needed? I've never seen this command in other languages. Is it only needed for leaving a subroutine with Goto?
The only similar command I can think of is the 'Exit' command in PowerBasic:
For i = 1 to 100
If i = 50 then Exit For ' This will exit from the 'For/Next' loop
Print i
Next
...continued
A silly example, but you get the idea. An exit out of a function or subroutine without 'Return' will cause an error in PowerBasic and many other languages.
Russell Jones
***I snatch kisses!***
So my question is: Why is FakeReturn even needed? I've never seen this command in other languages. Is it only needed for leaving a subroutine with Goto?
The only similar command I can think of is the 'Exit' command in PowerBasic:
For i = 1 to 100
If i = 50 then Exit For ' This will exit from the 'For/Next' loop
Print i
Next
...continued
A silly example, but you get the idea. An exit out of a function or subroutine without 'Return' will cause an error in PowerBasic and many other languages.
Russell Jones
***I snatch kisses!***
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by tranquil.
normaly I know this as Exit too. Or even Pop.
You have to use it if you leave a subroutine without a return so that the return-pointer is allways keeped on the stack.
hope you know what I mean with my ugly english
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home
normaly I know this as Exit too. Or even Pop.
You have to use it if you leave a subroutine without a return so that the return-pointer is allways keeped on the stack.
hope you know what I mean with my ugly english
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> Is [FakeReturn] only needed for leaving a subroutine with Goto?
Yes, so that if you choose to do that, you won't crash your app.
> An exit out of a function or subroutine without 'Return' will cause
> an error in PowerBasic and many other languages.
FEEL THE ...PURE... POWER!
> Is [FakeReturn] only needed for leaving a subroutine with Goto?
Yes, so that if you choose to do that, you won't crash your app.
> An exit out of a function or subroutine without 'Return' will cause
> an error in PowerBasic and many other languages.
FEEL THE ...PURE... POWER!
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by koehler.
Hmm, what about pop_return ?
Actually, I to only remember pop being used.
However, as there are so many people who actually have never heard of it, I would prefer almost anything to fakereturn. I don't know why, but it just makes me itchy for some reason...
Hmm, what about pop_return ?

Actually, I to only remember pop being used.
However, as there are so many people who actually have never heard of it, I would prefer almost anything to fakereturn. I don't know why, but it just makes me itchy for some reason...
-
- PureBasic Guru
- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm