Whattabout Gosubs? Little subscripts?

Hello people,

I have these few lines of code that are frequently showing up in the code.
And for the sake of making adjustments in that part of the code (and not to adjust every part of the same line of code through the whole code), and to keep the code compact, I wonder whatever happened to the basic command "Gosub" and "Return"?

Is there a way to direct the flow of the program to a little subroutine, do the chores, and go back to the point where you took off.
I cannot imagine something like that not existing anymore.
Is there a (manageable) way to create such a subroutine? :confused:

C/C++ never had “gosub” and “Return” is spelled “return”

In C/C++, they’re called “functions”.
They’ve been there forever

FTMZ:
Hello people,

I have these few lines of code that are frequently showing up in the code.
And for the sake of making adjustments in that part of the code (and not to adjust every part of the same line of code through the whole code), and to keep the code compact, I wonder whatever happened to the basic command "Gosub" and "Return"?

Is there a way to direct the flow of the program to a little subroutine, do the chores, and go back to the point where you took off.
I cannot imagine something like that not existing anymore.
Is there a (manageable) way to create such a subroutine? :confused:

I detect "BASIC" thinking. Look at "functions" when using C, C++. They always return the the line after the call to the function. ?And if you want, they can return a value you might use.

The Arduino sample programs in the IDE are full of functions.

Paul

OK… Upper of lower case is also something that did not matter in Basic (I guess I did not mention that I referred to Basic, with its Gosub/Return.)

Is there an example of such a function and how to use it?
I’ll take a look in the Reference part on this site and look for “return”.

Any advice is appreciated. :slight_smile:

FTMZ

Paul_KD7HB:
The Arduino sample programs in the IDE are full of functions.

Sorry, I missed out on that part.
Thanks. :wink:

Is there an example of such a function and how to use it?

setup() and loop() are functions, called from the hidden main program and are required for standard Arduino programs. In the Arduino IDE, select file>examples>... to see some examples.

A "return" statement is optional.

What’s the deal about little subscripts?
“byte” variables can be used for subscripts up to 255.

Hi FTMZ,

here is a tutorial about programming arduinos in C++. well explained
as you asked about "subroutines" here is the direct link to functions

startingelectronics.org/software/arduino/learn-to-program-course/15-functions/
If you find this chapter useful
start at chapter 1.
From basic you have a knowledge about the basic concepts of programming
but there are some specialties and differences betweeh basic and c++
So it makes sense to read all chapters.
best regards Stefan

You’re using functions now … probably just incorrectly calling them “voids” — i.e. setup() and loop().

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

@FTMZ: Arduino - FunctionDeclaration

Be aware that ‘return’ in C/C++ doesn’t mean exactly the same as in Basic.
In Basic it means the end of the subroutine, return execution of the code to where you came from. In C/C++ that meaning is implied just by having a } at the end of the function, the word return is not needed.

Return in C/C++ return is optional and used to indicate what value of variable will be returned to the calling function, there being no equivalent to that in Basic.

gfvalvo:
You're using functions now .... probably just incorrectly calling them "voids"

Naw, anyone the falls back on BASIC won't call them voids. They'll be GOSUB (s).

-jim lee

TheMemberFormerlyKnownAsAWOL:
What's the deal about little subscripts?

Not that type of subscript....
I think the OP is probably confusing SCRIPT and SKETCH
Therefore by SUBSCRIPT they probably meant SUB-SKETCH (i.e. SUBROUTINE)

I not only have a subscript, I have a superscript! In my sig.

Tx for all the replies and advice.
I was out for a while.
Besides all the codewords, I think I'll get it. :slight_smile: