So GOSUBs are functions in C/C++. E.g. digitalWrite and digitalRead are functions.
A function can return a value and can take parameters
/*
function that does not take parameters and does not return anything
*/
void someFunc()
{
...
...
}
/*
function that does not take parameters and returns an int
*/
int someFunc()
{
int someValue;
...
...
return someValue;
}
/*
function that takes two parameters and and returns a bool
*/
bool someFunc(int a, int b)
{
bool result = false;
...
...
return result;
}
When functions reach the end (indicated by }), they automatically return, so there is no need for a return statement.
However, you need a return statement if the function is specified to return something (2nd and 3rd example); the compiler will generate a warning in the line of "reaching end of non-void function" if you don't and you might end up with mysterious issues at run time.
There is no need for GOTO; in your BASIC example it's needed to prevent the code from continuing with the first GOSUB.
alf_onso:
What a difference, in my sites we are hungry to teach and help people. Sad.
So are we; most of us however take a slow approach where (initially) teaching is far more important than the actual solution.