possible to use conditional in subscripts?

Hi, I'm trying to get something like this to work:

1
2
3
4
//vector V[5][5]

V[ if(x) I-1; else J; ][K]
V[I][ if(y) K-1; else L; ]


Only it throws errors at every conditional. Right now I'm just setting variables outside the subscripts but I don't like the way that looks and I want to know if what I want to do is possible, since it seems easier to read.

I've looked around and can't find anything, any help would be greatly appreciated.
Ternary operator to the rescue:
1
2
V[ x ? I-1 : J ][ K ];
V[ I ][ y ? K-1 : L ];


http://en.wikipedia.org/wiki/%3F:

Hope this helps.
Last edited on
Holy wow that's amazing!

Thanks for the fast response!

[edit]That got rid of 63 lines of code! AND it's more readable!
Last edited on
Just doing my Bat-Duty.
Keep up the good work, citizen.
;-)
Topic archived. No new replies allowed.