i < 10, j < 10
is allowed but probably isn't what was intended as it discards the result of the first expression and returns the result of j < 10 only. The Comma Operator evaluates the expression on the left of the comma, discards it then evaluates the expression on the right and returns it.
(Collected) https://stackoverflow.com/a/17638765/5610655
If you want to test for multiple conditions use the logical AND operator && instead. Btw, comma-separated conditions run fine in my IDE.
Similar concepts have also been discussed previously. Have a look.
C++: Multiple exit conditions in for loop (multiple variables): AND -ed or OR -ed?
Are multiple conditions allowed in a for loop?
Here's a practical example. If you run the code given below, you'll see that it is outputting 10 times than 2 times
#include <stdio.h>
void main()
{
int i,j;
for (i = 0, j = 0; i < 2, j < 10; i++, j++) {
printf("Hello, World!");
}
}
--output----
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!
If you want both conditions to be effective, use AND(&&) operator instead of the comma-separated condition.
#include <stdio.h>
void main()
{
int i,j;
for (i = 0, j = 0; i < 2 && j < 10; i++, j++) {
printf("Hello, World!
");
}
}
---output--
Hello, World!
Hello, World!
It's unnecessary to use AND separated multiple conditions, only one will condition will suffice. The condition with fewer iteration steps will only be executed and the loop will break.
#include <stdio.h>
void main()
{
int i,j;
for (i = 0, j = 0; i < 2; i++, j++) {
printf("Hello, World!
");
}
}
---output--
Hello, World!
Hello, World!