Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In this week's episode of "YOUR DOING IT WRONG"
- void Main()
- {
- // The ** OLD ** keyword-heavy way to write a for loop.... nobody does this any more...
- for (int i = 0; i < 12; i++)
- {
- Console.WriteLine(i);
- }
- // WHY memorise all that custom syntax, that *only* applies to `for` statements.
- // MUCH better to have general principles that are used everywhere and just use those.
- //The NEW way to write a for loop... uses the proprietary fforr function... no keywords!
- fforr(() => 0, i => i < 12, i => ++i, (i) =>
- {
- Console.WriteLine(i);
- });
- }
- public void fforr(Func<int> iCreator, Predicate<int> test, Func<int, int> incrementi, Action<int> doAction)
- {
- var i = iCreator();
- while (test(i))
- {
- doAction(i);
- i = incrementi(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement