looping only X times???

my code runs in an endless loop by design but there is a section of it that i would only like to run X times. that section is within the endless loop and it must be there.

if i use a for loop and set i to X it will only loop X times BUT then when the entire code loops around, that for loop will go for another X times.

follow me?
how can i make a certain part of the code only loop X times?

i have a call_back function as well, if that helps.
Use a for loop?

1
2
3
4
for (int i=0; i < 5; i++)
{
   cout << "Loop number: " << i << endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main()
{
     bool executed = false ;

     for ( ;  ; )
     {
           // ...

           if ( !executed )
           {
                 for ( /*...*/ )
                      ;
                 executed = true ;
           }

           // ...
     }
}
Last edited on
thank you for the suggestions.
turns out, i needed to add a bool statement to my constructor and then it would work as that only executes once.

i probably gave too little info in regards to how my code is structured but thanks anyway, i learned something!
Topic archived. No new replies allowed.