This is more like an exercise. I have several conditions that affect 2 nested for clauses:
for(...)//1st { for(...)//2nd { ... } } and since there are various possibilities (each one for a condition) respectively the for1 and for2 can vary.
For example the first for can be
for (int row = 0; row < numRows; row++) or
for (int row = numRows - 1; row >= 0; row--) so not only changes thes start-end but also the increase/decrease (++ or --)
So i thought that if it was possible to "encapsulate" the for cycle it would have been easy.
Something like (pseudocode)
if(condition1) for1=... else for1=... if(condition2) for2=... else for2=... for1 { for2 { ... } } --ADD-- The code itself is pretty simple.
for (int row = numRows - 1; row >= 0; row--) { ... for (int column = 0; column < numColumns; column++) { ... } } but if I have the option FlipVertical the first for becomes
for (int row = 0; row < numRows; row++) and if I have the option FlipHorizontal the second for becomes
for (int column = numColumns-1; column >=0; column--) Again this is not complicated at all. I just wanted to have hints for solving it in a smart, simple and compact way.
And yes I do need the indexes row and column
Thanks
Enumerable.Reverse. If you do need the index I would be careful to not make things more difficult to read and understand.forto run inside method of some other class, constructed with all required parameters. It's somewhat common to create static helper methods (often generic) accepting delegate (in your case body of innerfor) to run it in the loop with different parameters. Even better is to create extension method, but you need a specific type, e.g.IEnumerable<Item>. Be more specific for a better answer. Also consider codereview, maybe your approach is far from ideal (e.g. can be replaced with a linq).