News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Problem with EndFunction

Started by thaaks, August 27, 2005, 12:53:58 PM

Previous topic - Next topic

thaaks

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

empty

#1
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! ;)

kevin

#2
My ears are burning..  but if it's not in the request thread, then it's not on my list :)

Fluorescent

NO on your list, or ON your list ??

thaaks

@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

kevin

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..  :)

empty

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.