Is there a way for a while loop to consistently check if the condition is met?
Example:
int x = 2;
bool condition = true;
while(condition){
//code
if (x == 2){
condition = false;
}
// other code
}
//outside of while loop
My question is: is there a way to make the while loop consistently check if the condition is being met? I'm new to C# and struggling on this.
5 Replies
not sure what you mean. you can use
break;
to exit the loop?what do you mean by consistently?
by definition a while loop checks the condition every iteration
I mean throughout the iteration
then you'll want to
break;
out of the loop early like alex suggestedAh, ok, ty