C
C#12mo ago
Lee OH

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
alex
alex12mo ago
not sure what you mean. you can use break; to exit the loop?
Jimmacle
Jimmacle12mo ago
what do you mean by consistently? by definition a while loop checks the condition every iteration
Lee OH
Lee OHOP12mo ago
I mean throughout the iteration
Jimmacle
Jimmacle12mo ago
then you'll want to break; out of the loop early like alex suggested
Lee OH
Lee OHOP12mo ago
Ah, ok, ty
Want results from more Discord servers?
Add your server