This question already has answers here:
No loop condition in for and while loop
(5 answers)
Closed 7 years ago.
How does an empty for works?
I have seen this code (and works perfectly)
for(;;) {
And I can't comprehend how is this working or why
It is exactly like while(true).
It skips all the conditions so it just empty-executes since in for the expressions are all optional (i.e. you don't have to provide them if you choose not to).
Related
This question already has answers here:
Integer literal with single quotes? [duplicate]
(2 answers)
Is there a way to write a large number in C++ source code with spaces to make it more readable? [duplicate]
(6 answers)
Closed 2 years ago.
I recently came across the following C++ code snippet:
int Mod = 998'244'353;
I was intrigued by the use of single quotes in this number.
Could someone elaborate on what this gets interpreted as and why is it accepted?
Also has this formatting always been there in c++?
This question already has answers here:
What is wrong with using goto? [duplicate]
(6 answers)
GOTO still considered harmful? [closed]
(49 answers)
Closed 3 years ago.
In my CPP class my professor strictly asked us to not to use goto statement as long as possible. Why is so, as I think there are no memory or any issues whatsoever with goto?
This question already has answers here:
How does the Comma Operator work
(9 answers)
Closed 4 years ago.
I was practicing practicing some programming and by mistake wrote the following line of code :
int a,b;
cin>>a,b;
Can anybody explain what the comma does here and why doesn't the compiler show any error.
It means that the whole expression has the value b.
But because b is not initialised the behaviour of your code is undefined!
Modern compilers can warm you of this.
This question already has answers here:
Kotlin: Why can't I do an assignment in a loop guard?
(4 answers)
Closed 4 years ago.
Greeting, You! I am learning Kotlin and I am struggling to use while loop to get answer from user. Not just that, if you could help explain how to use while loop to me, I would be really appreciate and thanks in advance.
You should use while(ans == 'Y').
In condition checking you should make use of == to check equality
And also in order to get repeated input put the readLine statement inside while loop.
This question already has answers here:
What does "for(;;)" mean?
(5 answers)
Closed 7 years ago.
Simple question: I've been looking over boost's asio library, and keep coming across code like this.
for(;;){
//something
}
There's an example of this here.
Can anyone elaborate as to what using ";;" within a for loop does? I can't seem to understand it.
Its a simple infinite loop syntax, a complete code looks like this
for(<initialize>; <condition>; <increment/decrement>) {
<body>
}
Those I labelled with '< .. >' are optional.