fork(1) download
  1. using System;
  2.  
  3. namespace test
  4. {
  5. class Program
  6. {
  7. static bool isUpperArrival = false;
  8. static bool isLowerArrival = false;
  9. static void Main(string[] args)
  10. {
  11. var upper = 10;
  12. var lower = -10;
  13. var num = 7;
  14. Console.WriteLine(num);
  15. for (var i = 0; i < 100; i++)
  16. {
  17. if (ShouldUp(num, lower, upper))
  18. num++;
  19. else
  20. num--;
  21. Console.WriteLine(num);
  22. }
  23. Console.ReadLine();
  24. }
  25. static bool ShouldUp(int number, int lower, int upper)
  26. {
  27. if (number <= lower)
  28. {
  29. isLowerArrival = true;
  30. isUpperArrival = false;
  31. return true;
  32. }
  33. if (number >= upper)
  34. {
  35. isLowerArrival = false;
  36. isUpperArrival = true;
  37. return false;
  38. }
  39. if (isLowerArrival)
  40. return true;
  41. if (isUpperArrival)
  42. return false;
  43. return false;
  44. }
  45. }
  46. }
  47.  
Success #stdin #stdout 0.01s 131520KB
stdin
Standard input is empty
stdout
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-9
-8
-7