What does double semicolon ";;" in C++ programming langauge? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does double semicolon ";;" in C++ programming langauge?

I can not find any proper answer to my question on Internet, so I hope someone here would help me.

11th Dec 2019, 8:31 AM
Mikolaj Grodon
Mikolaj Grodon - avatar
5 Answers
+ 10
You know that a statement has to be ended with a semicolon, right? A single semicolon is just an empty statement. You could string up as many as you want, and nothing would happen. Two semicolons can also occur in for loops: for(;;) { ... } In this case, all three 'slots' are empty, nothing is initialized, or incremented, and there's no condition for when the loop should run. This is a way to write an eternal loop that can only be left from inside the block with a break statement.
11th Dec 2019, 8:47 AM
HonFu
HonFu - avatar
+ 3
Also works similarity in C, Java and C#.
11th Dec 2019, 11:36 AM
Sonic
Sonic - avatar
+ 2
I see, thank you! You made my day.
11th Dec 2019, 8:58 AM
Mikolaj Grodon
Mikolaj Grodon - avatar
+ 1
I would disagree about breaking for(;;) You can also break it with "return" or "goto" (or any terminating function like exit)
12th Dec 2019, 9:50 PM
Sergey Knyazev
Sergey Knyazev - avatar
+ 1
Yeah, or by turning off your computer.
12th Dec 2019, 9:54 PM
HonFu
HonFu - avatar