I'm new to iOS-Developement and my question is if it is possible to run some action a fix set number of times.
I want to perform an action for exactly 20 times.
            Asked
            
        
        
            Active
            
        
            Viewed 1,176 times
        
    1
            
            
         
    
    
        lukas
        
- 2,300
- 6
- 28
- 41
- 
                    4If the answer to your question is really "[for loop](http://en.wikipedia.org/wiki/For_loop)" you might want to take a step back and start with a book or tutorial series that starts at the very beginning. – Matthias Bauch Feb 23 '14 at 11:55
- 
                    If you're just starting out, asking questions on Stack Overflow is not the place you need to be. You should find a good book or a series of online tutorials. Have a look at [Good resources for learning ObjC](http://stackoverflow.com/q/1374660). The Big Nerd Ranch books are excellent, and lots of people like the Stanford iOS course on iTunes U. Good luck! – jscs Feb 23 '14 at 20:33
2 Answers
2
            I dont really know what you want but it seems you are looking for
int i;
for(i=0;i<20;i++)
{
     //do your action.
}
also if you want it to be performed in background and not on main queue 
you can use  GCD
or NSThread
and put for inside GCD or NSThread.
 
    
    
        Coldsteel48
        
- 3,482
- 4
- 26
- 43
0
            
            
        What I understand from your question is that you're looking at a classic for loop in Objective -C. Here's how it goes
for (/* Instantiate local variables*/ ; /* Condition to keep looping. */ ; /* End of loop expressions */)
{
    // Do something.
}
for (int i = 1; i <= 20; i++)
{
    NSLog(@"%d", i);
}
If you wish to loop through objects in an Array its the same
for (NSString* currentString in myArrayOfStrings)
{
    NSLog(@"%@", currentString);
}
You can also use the while loop
while(number<= 20)
{
//do something
}
 
    
    
        lukas
        
- 2,300
- 6
- 28
- 41
- 
                    for the `while` loop don't you want to instantiate the `number` and add the `number++;` somewhere in the `while` so it won't be an endless loop ? – Coldsteel48 Feb 23 '14 at 12:02