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.
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.
+ 3
Also works similarity in C, Java and C#.
+ 2
I see, thank you! You made my day.
+ 1
I would disagree about breaking for(;;)
You can also break it with "return" or "goto" (or any terminating function like exit)
+ 1
Yeah, or by turning off your computer.