+ 3
Multiple conditions in for loop c++
Can I put conditions which contain (&& , || ) in a for loop? i.e : for(i=1 ; x>3 && !test ; i++ )
3 Respuestas
+ 4
In the beginning of your loop, do an IF condition for !test. If it's test, then 'break;' the loop to end it. Get what I mean? That's best way to go about it.
However, to properly answer you, yes you can do that. I'd organize things with the expectations that others will use it also and so things should be readable to the best of your ability.
https://code.sololearn.com/c7KokF2VMwaf/#cpp
#include <iostream>
using namespace std;
int main() {
bool test = false;
for(int i = 0; i < 3 && !test; ++i) {
cout << "Test!";
test = true;
}
return 0;
}
+ 2
thank you guys