Advertisement
avr39ripe

cppCycleLoop

Feb 9th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 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.  
  10.     int loop{ maxLoop };
  11.     int loopStep{1};
  12.  
  13.  
  14.     while (true)
  15.     {
  16.         if ((loop >= maxLoop and loopStep > 0) or (loop <= minLoop and loopStep < 0))
  17.         {
  18.             loopStep *= -1;
  19.             std::cout << '\n';
  20.         }
  21.  
  22.         if (loop >= minLoop and loop <= maxLoop)
  23.         {
  24.             std::cout << loop << ' ';
  25.         }
  26.  
  27.         loop += loopStep;
  28.         std::this_thread::sleep_for(std::chrono::milliseconds(200)); //make some pause for better output look :)
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement