-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow function return values using EXIT FUNCTION [returnvalue]
#212
Comments
What's wrong with this? All this just to save the additional error assignment? Would seem rather confusing to me to place anything after FUNCTION foo
IF wrong THEN foo = failed: EXIT FUNCTION
foo = success
END FUNCTION |
EXIT FUNCTION [returnvalue]
EXIT FUNCTION [returnvalue]
Nothing really. I've always used that with QB45. With VB, I switched to using |
I'd definitely use it. If anything, just to force people to upgrade their version of QB64pe so they can run my code 😁 |
I don't know about the proposed syntax (that's easy to change, however), but I think it's worth it to add this since it allows you to avoid writing the function name everywhere you return a value. With the way it currently works if you rename a function you have also change every spot a value is returned, and if you miss one you don't necessarily even get an error. Having a Certainly it's not strictly necessary, but then many of the existing statements are not actually "necessary", they exist purely because they can be used to make your code better. IMO this falls into that same category. I will say I like the |
However, if it gets implemented some day, then for consistency |
This is an excellent point.
Now that you said that, I too see the ugliness. 😄 ASM-like |
Why not just |
I think the risk of mistakes is a bit high, leaving off the parenthesis would produce a valid (but different) statement. You would likely get an error (unless you were really unlucky) but it would be confusing. |
To bring in another idea, |
I like this. |
_RETVAL works for me, since RETURN is taken. It's verbose, in the spirit of BASIC, and not a ton of typing. |
Sure, but |
In my opinion, EXIT FUNCTION [return value] is the best because we have EXIT CASE, EXIT DO, EXIT WHILE, EXIT FOR, and EXIT FUNCTION |
This was originally requested in QB64Team/qb64#225 using the keyword
RETURN
.However, the
RETURN
keyword is used while returning from GOSUBS and can take an optional label which can lead to complications if it doubles as a return statement forFUNCTIONS
.Hence, the suggestion is to use the following syntax:
Leaving the below link here for future discussions.
https://qb64phoenix.com/forum/showthread.php?tid=1100
The text was updated successfully, but these errors were encountered: