Is it possible to have two different voids acting as a loop

I was writing a code with multiple voids and was wondering if there's a key word or something to write at the beginning of the void to make act as a loop and not just run once.
Any help would be appreciated. :v:

They're called functions, not voids, and no, there is no single keyword that will make them loop

You mean that you were writing some code with multiple functions, none of which returned a value and hence were declared void

If you want a function to loop until some condition is met then look at using a while loop, but make sure that it is possible for the code to exit the while loop otherwise it will repeat the code endlessly

If you want a function to loop a fixed number of times then look at using a for loop

NOTE : once in the loop of either kind only the code in that loop will be executed

Thank you so much! I completely forgot about using a while loop.

as long as the functions loop1 and loop2 are not blocking and fast you could do something like this to call the function at every iteration of the loop().

void loop1() {...}

void loop2() {...}

void loop() {

Make sure that you use it properly. Too often we see while loops with no way to exit or taking so long to execute that they interfere with the responsiveness of the sketch

you can simply mention a function in void loop and then write it outside void loop

for example

int led = 13;

void setup(){

void loop(){

void led(){

You don't call the Serial.print function "int Serial.print", so why call the loop function "void loop"?

sorry i didnt mention function

Serial.print() is not a function. .print is a method in the object Serial. Since every Arduino has at least one serial port, the IDE creates the Serial object for you.

But isn't "method" just another name for a function inside an object?

Yes, but in the object code the function will have a type.

EVERY function has a type...

C++ does not have methods.
The word, in the context of a generic OO function, does not exist in the standards.
C++ has functions.

C++ has operators and functions

In case of a class and within the context of that class, it’s a member function

So function is the right word.

You put the code you want to run once in void setup().
You put the code you want to run over and over in void loop().

pseudocode ---- not compiled, not tested, not detailed

const byte buttons = 2;
byte buttonIndex;  // which button to check/process during void loop()
byte buttonState[ buttons ];  // if multiple button states are needed, keep them!

void loop()
    static unsigned long nowMicros = micros();
    task0();  // watches buttons, sets state 
    task1();  // processes button state(s) into led blink rate
    task2();  // blinks led

Once you get the delays out of your sketch it becomes possible to run void loop() at over 50KHz, that's > 50 times per millisecond.

Just in case there is any confusion, only one function can be executed at a time in the normal Arduino environment

ah, ok :+1:

I posted the clarification because there is an implication in the topic title that you wanted to run 2 looping functions at the same time

Is that what you are aiming to do ?
If so, then there are ways of achieving the same effect by different means

And if you write them well, the lot will run in 50 microseconds or less, like 20 usecs.

If I toggle a led every 200 msecs while watching a pin and checking Serial for commands at the speed of my loop(), as long as each task is done on time then are they not running smoothly in the same time period?

You can up to 8 digital pins in one cpu cycle and even that isn't perfectly "same time" but in practical sense, 8 pins read within 62 nanoseconds is close enough for me!