So here's that piece of code, very basic but i just can't find any similar questions that have two variables in the while loop with cin in it.
void Perm(int start, int end, int a[]) {
//some recursion code
}
int main() {
int i, n, a[10];
while (cin >> n, n) {
for (i = 0; i < n; i++)
{
a[i] = i + 1;
}
Perm(0, n, a);
}
return 0;
}
Can't figure out what does while (cin >> n, n) part do, and when will it stops. It looks like when I run the code, the input is just required once..
In the condition of the while statement
there us used the comma operator.
That is the expression consists from two subexpressions,
cin >> nandn, that are executed sequentially. The result of the condition is the value of the second subexpression that is implicitly converted to the type bool.From the C++ 17 Standard (8.19 Comma operator)
The while loop can be equivalently rewritten like
It would be more safer to write the condition of the while statement like
Instead of the comma operator it would be better to use the logical AND operator like for example