Re: Structure tutorial, a question
-
This post is deleted! -
My guess is that it's needed for the preprocessor to correctly find the end of the function.
"return" marks the end of the code started at "function" (just as "endstruct" ends "struct", for example), and the correct syntax for "return" is "return <parameter>"
-
Your function will never exit. It has an endless loop :)
-
@Martin said in Re: Structure tutorial, a question:
Your function will never exit. It has an endless loop :)
I think you're missing my point but that's fine it was not important
-
@Nisse5 said in Re: Structure tutorial, a question:
My guess is that it's needed for the preprocessor to correctly find the end of the function.
"return" marks the end of the code started at "function" (just as "endstruct" ends "struct", for example), and the correct syntax for "return" is "return <parameter>"
I think that's probably the reason, thanks!
-
Think of it like this. It's a function that once entered, it will never exit. However, you still need to get into the function, right? Perhaps this function is at the start of your code, and your entry for your code comes after. How would the system know where to start in this case? This is one reason why you need to have your functions closed.
-
it is simply because a function is a complete block of code that can be called (executed) from anywhere else. "Function" marks the start, "Return" marks the end and in the case of Fuze the return type must be specified on the end (some languages put it at the start). I hadn't written one that did not need to return something yet so I did not realise void was necessary. Honestly, in the code above, it's not really required but the interpreter will complain without it because without it, it will be an invalid function declaration.
-
Maybe it's a little petty, but perhaps it would have been better if the end of a function was called "endFunction", and use the return command (including its return void equivilent) just before it while allowing it to be used elsewhere within a function, like for an early exit. Something like this...
function isStrNotChr( strdata ) if len( strdata ) < 2 then return 0 endIf return 1 endFunction
-
@Discostew that's an interesting thought and this may have helped me get my head around it a little quicker, but once I'd realised that a function must always return something, even if that something is nothing, the return void clicked with me.
@SteveZX81 think of it as the end if to your if. If you don't need it to return anything, return void, otherwise return whatever you need :)