I'm in a situation where it would be really nice to be able to determine what boolean expression I use for the terminating statement of a for loop at runtime. Or in more simpler words, decide whether I want i > 0, or i < file.length and decrement or increment i
respectively. I know you can use lambdas to make the iterator either decrement or increment at runtime, explained in this SO question, but is something along the same lines possible for the terminator?
From trying to attempt this myself with System.Action
to act as an anonymous function so I can still access the objects the for loop uses whilst inside action having some logic to determine whether or not I go forwards or backwards (this ended up with me realising that this wont work), it seems as if this is very much so the case of, if it is possible, it's far more complicated and is not worth the boilerplate code required compared to just having two loops within an if/else statement. I can't be the only one that has wondered this, surely!
EDIT: For those who do not understand what I'm asking, focus on the first paragraph, the second just describes my efforts. itsme86's answer describes pretty succinctly what I wondered was possible, providing it runs of course.