avr39-ripe

cycleLoopAdvanced

Jun 27th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <thread>
  4.  
  5. int main()
  6. {
  7.     const int maxLoop = 10;
  8.     const int minLoop = 0;
  9.     int loopStep = -1;
  10.     int loop = 10;
  11.  
  12.     while (true)
  13.     {
  14.         if ((loop >= maxLoop and loopStep > 0) or (loop <= minLoop and loopStep < 0)) { loopStep *= -1; std::cout << "\n"; };
  15.         std::cout << loop << ' ';
  16.         loop += loopStep;
  17.  
  18.         std::this_thread::sleep_for(std::chrono::milliseconds(200)); //make some pause for better output look :)
  19.     }
  20. }
Add Comment
Please, Sign In to add comment