Passing a function to another function with arguments

// this is a function I modified from this site to do away with for multiple loops
// I hope this helps someone

// need forward declarations here
void FromTo(void (*), int From, int To, int Step);

void setup() {
Serial.begin(9600);
// put your setup code here, to run once:

}

void loop() {
// no need to use multiple for loops
FromTo(PrintOut, 0, 10,1);//example forward loop
FromTo(PrintOut, 10, 0,2);//example Backward loop with step of 2

}

void FromTo(void (*function)(int Value), int From, int To, int Step) {
if (From < To) {
Serial.println("UP");
for ( int i = From; i < To; i+=Step) {
(*function)(i);
}
} else {
Serial.println("DOWN");
for ( int i = From; i > To; i-=Step) {
(*function)(i);
}
}
delay(5000);
}

void PrintOut(int Value) {
Serial.println(Value); //watch on your serial monitor
}

A decent example of a function pointer if one was needed. Welcome to the forum. Consider using code tags next time so people can easily read and copy your code.

The forward declaration isn't needed in an Arduino sketch because the one automatically provided works fine.

One problem with using a function for your loops: the function has no read or write access to any of your local variables.