Two Semicolons

Hi all!

I was reading through some questions on the General C++ Thread, and I came across the following code, from which I don't understand the two ;;'s:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <thread>
#include <chrono>
void fn()
{
    for(;;)
   {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        // <-- call your function here
   }
}
int main()
{
    std::thread(fn).detach();
    // <- do something that takes more than a second here
}


Can anybody explain how this can be correct?
Thanks in advance!
closed account (zb0S216C)
Two adjacent semi-colons in a for loop is considered to be an infinite loop; it's equivalent to:

1
2
3
4
while(true)
{
    // ...
}

Wazzak
See here for the general structure of a for loop:
http://www.cplusplus.com/doc/tutorial/control/#for

When the condition part is left empty, it is implicitly true.
Thanks! I understand!
Topic archived. No new replies allowed.