Advertisement
Guest User

Untitled

a guest
May 25th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // In this week's episode of "YOUR DOING IT WRONG"
  2.  
  3. void Main()
  4. {
  5.  
  6. // The ** OLD ** keyword-heavy way to write a for loop.... nobody does this any more...
  7. for (int i = 0; i < 12; i++)
  8. {
  9. Console.WriteLine(i);
  10. }
  11.  
  12. // WHY memorise all that custom syntax, that *only* applies to `for` statements.
  13.  
  14. // MUCH better to have general principles that are used everywhere and just use those.
  15.  
  16. //The NEW way to write a for loop... uses the proprietary fforr function... no keywords!
  17. fforr(() => 0, i => i < 12, i => ++i, (i) =>
  18. {
  19. Console.WriteLine(i);
  20. });
  21. }
  22.  
  23. public void fforr(Func<int> iCreator, Predicate<int> test, Func<int, int> incrementi, Action<int> doAction)
  24. {
  25. var i = iCreator();
  26. while (test(i))
  27. {
  28. doAction(i);
  29. i = incrementi(i);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement