TheDarklingWolf/Cataclysm-DDA — pull request #946 by adzeitor (2013-05-11 11:40:44+00:00)
Title: Ternary fix

```c
for (int i = -1; i <= 1; i += 2)
{
for (int j = 0; j <= 1; j++)
{
// Apply the adjustment to x first, then y
const int adj_x = 5 + !j?i:0;
const int adj_y = 10 + j?i:0;
printf("%4d %4d\n" ,adj_x, adj_y);
}
}
```

prints (checked in clang 3.0, gcc 4.7.3):
```
-1 -1
-1 -1
1 1
1 1
```

I have simplified this method, but you can just add parentheses:

```c
for (int i = -1; i <= 1; i += 2)
{
for (int j = 0; j <= 1; j++)
{
// Apply the adjustment to x first, then y
const int adj_x = 5 + (!j?i:0);
const int adj_y = 10 + (j?i:0);
printf("%4d %4d\n" ,adj_x, adj_y);
}
}
```

```
4 10
5 9
6 10
5 11
```