# Thread: What is the difference between the two for loops?

1. ## What is the difference between the two for loops?

Hi,

I'm reading this programming book and it gives a sample code:
Code:
```int get_maxpos(int x[], int eff_size)
{
int i, maxpos = 0;

for (i = 0; i < eff_size; i++)
maxpos = x[i] > x[maxpos] ? i: maxpos;
return maxpos;

}```
I thought the book has made a mistake so i type the code into my compiler as:
Code:
```int get_maxpos(int x[], int eff_size)
{
int i, maxpos = 0;

for (i = 0; i < eff_size; i++)
{
maxpos = x[i] > x[maxpos] ? i: maxpos;
}

return maxpos;
}```
My correction turn out to be wrong since the results are different. Can you please explain to me what is the difference from having the bracket and not have a bracket?

Also, for this part: "maxpos = x[i] > x[maxpos] ? i: maxpos; " what does the "? i:" means?

Thank you

2. ## A simple one

The brackets separate the rest of the code from the for loop code! If you have only one line of code for the for loop, you do not need to put brackets! However, I think you are required to have them when you have more lines of code for a loop

3. For this part: "maxpos = x[i] > x[maxpos] ? i: maxpos; "

Can someone explains to me what "? i:" means?

Thank you!!

4. ahhh...thank you!

5. My correction turn out to be wrong since the results are different.
So putting the braces in the for loop gave you different results? That doesn't make sense. From what I can see, the for loop should act the same with or without the braces.