# Thread: for loop that calls multiple functions

1. ## for loop that calls multiple functions

Hi there, I just wanted to ask if the plan I had for this code solution was even possible before i start figuring out how to do it.

the program has a [12][7][7] uninitialized array and will populate it using for loops, but each of the 12 [7][7] sections will have a different pattern in them. will it be possible to create a for loop that as it moves through the [12] section calls a different function each time?

I'm pretty sure it could be done using 'if' and 'else if', but I'm not sure if functions can be called like that? I'm also not sure if there would be a more streamlined way to do it such as changeing the name of the function called depending on the value of k

I'm not sure if I've explained that very well, so just say if it needs clarifying. Bellow is a bit of pseudo code to try and better explain it

Code:
```//using if/else if

for (k=0; k < 12 ; k++)

if k=0 (function1() )

else if k=1 (function2() )

else if k=2 (function3() ) etc

functions defined here```
Code:
```//using method I'm pretty sure wouldn't work

for (k=0; k < 12 ; k++)

function(k) ()```

2. The first method looks ok (as long as you realize it's pseudo-code), and I don't understand what you're doing in the second method. A better way might be to use a switch statement:
Code:
```for (k=0; k < 12 ; k++)
{
switch(k)
{
case 0:
function1();
break;
case 1:
function2();
break;
case 3:
function3();
break;
}
}```

3. thanks for the replies, since I'm new to C++ I wasn't sure if what I was thinking was something I could do.

what I was trying to show in the second pseudo block was a loop where the name of the function called would change with the value of k. Like I said, I'm pretty sure this wouldn't work, but I thought I'd check.