Hi, I am still porting my BlitzBasic game to PlayBasic and stumbled across the following:
It seems to me that in PlayBasic I have only one exit point per function to return some value which is at the end of the function.
Sample code in Blitz Basic:
Function test(a)
If a < 5
return a
return a*2
End Function
To do something similar in PlayBasic I have to code the following:
Function test(a)
Local b
If a < 5
b = a
else
b = a * 2
endif
EndFunction b
The more complex the function gets the more cumbersome gets the coding :(
Don't you think that a Return <values> for functions would make sense?
Or did I just miss something and the functionality is there?
Cheers,
Tommy
Well you could use Exitfunction. Perhaps not beautiful, but it'd make porting easier, I think.
Function test(a)
If a < 5
ExitFunction a
EndFunction a*2
// or
Function test(a)
If a < 5
ExitFunction a
ExitFunction a*2
EndFunction 0
QuoteDon't you think that a Return <values> for functions would make sense?
Hehe. Hello, Kevin! ;)
My ears are burning.. but if it's not in the request thread, then it's not on my list :)
NO on your list, or ON your list ??
@empty: Thanks, ExitFunction completely slipped my investigation. And I thought I read the functions tutorial in detail. Must have been either too late or too much wine last night.
@Kevin: The request is in ;) . Although I must admit that ExitFunction is fine, too. But I still think it's cumbersome and confusing to have two different keywords to leave a function with valid return values...
Thanks for your help!
Tommy
Functions in PB allow local scope labels and as such, local subroutines within functions. As a result, Return & Exitfunction are not really interchangeable in all circumstances. But anyway, the current function syntax is (still) modeled upon DarkBasic syntax. Which is already on the endangered list.. :)
QuoteBut I still think it's cumbersome and confusing to have two different keywords to leave a function with valid return values...
ExitFunction makes sense, cause we have ExitFor, ExitWhile etc as well. So having two keywords (one to break out of a block and one to normally end it) is consistent.