Repeat A certain Number Of Times?

Please excuse me if this is the wrong area.

I am making a program where I want it to repeat one void a certain number of times, and then repeat another void a certain number of times.

I know that I can just repeat the call out for the void, but I dont want to have to do that. I want to call it out once, and have a repeat thing that repeats it say 6 times. I would have a val in the pin declare section. That could be changed to change to a repeat from 6 to a 2, 5, 90, ect.

In C and C++ the canonical way to do something “n” times (where “n” can be a numerical constant or a numerical variable or any kind of expression that evaluates to a numerical data type) is, for example

    int i;
    int n;
    // Code to get some value of "n"

    for (i = 0; i < n; i++) {// Loop to do "something" n times
        // Do "something"

Take a gander at for some “for” details.

There’s even an example at that shows a loop where the loop counter is a pin number that changes from one pass through the loop to the next.



Thank you! I did it, and it compiles perfectly. If you want to see what it is for, look at my new thread in the Exibition section. It is titled "4 Digit 7 Segment Tester".

I am making a program where I want it to repeat one void a certain number of times, and then repeat another void a certain number of times.

Not to be too picky, but, void is a function return type. What you want to do is a call a function a certain number of times.


Not to be too picky, but in this context, "void" is a function "lack-of-return" type. :)


This works more like a void setup. It runs once every time you call it out. If you look at the code I posted earlier, I am doing a void segments and a void digits. I have to call those out.

Heh???? Did that make sense to anyone?

What exactly are you trying to say?

Did that make sense…

PaulS already tried, but heck, I’ll take a shot at it too:

He has two functions:

1. A function named segments. The return type of the function is void. (See Footnote.)

2. A function named digits. The return type of the function is void.

The code in his sketch invokes those functions, here and there.

How did I do?



Note to the World: Unless you really like to suffer, I recommend that you snip on the dotted line and discard everything below. Really.


Before we get into a pi$$ing match about what the heck “void” means in C, I’ll note that it is clearly spelled out on the C language standard, ISO/IEC9899:1999(E), in chapter 6.2.5 Types

Except for the stuff in quote marks below, I paraphrase, to make it simpler. (Yes, really.)

In paragraph 1, it says that void is a type that is in the category of incomplete types, where an incomplete type is defined as one of the
types that describe objects but lack information needed to determine their sizes.”

And a little further along, in paragraph 16:
The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

There is a lot of stuff about what you can’t do with a void type, but the bottom line is that you can’t declare an object of type void, but you can declare a function with a void return type. A void expression is evaluated for its side effects (like calling a function with void return type), but you can’t convert the value of a void expression to something that is not void.

C++ inherits most of the characteristics of C, including the void type, but the language specification writers “enhanced” the narrative a little.

The C++ standard, ISO/IEC 14882:2003(E), has the following in paragraph 9 of Chapter 3.9.1 Fundamental Types:
The void type has an empty set of values. The void type is an incomplete type that cannot be completed. It is used as the return type for functions that do not return a value.

Now, is that clear enough for everyone? Yeah, I thought so.

I mean, do we really need to go into all of this to answer a question from a Poster who needed to know how to make a for loop but didn’t know there was such a thing? Really? I mean, if reading this kind of stuff gives you a headache, I did recommend that you not read it, right?

Let me try to explain it better...

You only write the voids once. This could be hundreds of lines of code. And then you could do another void. In your actual void loop you could call out that 200 line void 6 times, and it would only be 206 lines, not 1200 lines...

If you wanted to call out 3 different scripts in a random order, you could have void a, void b, and void c. In your void loop, all you have to do is something like

void loop()

Or something like that...

Ouch! Ouch! Ouch! My eyes are bleeding :)

Please don't call them "voids". If they were "int" functions, would you call them "ints"? Just call them "functions", which is what they are. The word "void" is like an adjective that tells what type of value the function returns. "void" means that the function doesn't return a value.

So, instead of saying "void loop", you could just say "loop function", or you could use the C notation and write "loop()" so everyone would know you are talking about a function.