D
D
Denis2021-07-18 23:32:43
C++ / C#
Denis, 2021-07-18 23:32:43

C++ How to slow down the execution of a while loop?

I have a loop:

while(y != 20)
{
    y++;
}

How can I make it increase by one every second?
That is,
1
(one second)
2
(one second)
Etc.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
cunion, 2021-07-20
@NeYmen

#include <thread>

int main(int argc, char** argv)
{
  int y = 0;
  while (y >= 20)
  {
    std::this_thread::sleep_for(std::chrono::seconds(1));
    y++;
  }

  return 0;
}

I
Ighor July, 2021-07-19
@IGHOR

https://www.codegrepper.com/code-examples/cpp/c%2B...

R
res2001, 2021-07-19
@res2001

Add a 1 second pause inside the loop.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question