Link to home
Start Free TrialLog in
Avatar of sneeri_c

asked on

C# Do / While Statement

I am trying to write a Do Statement that will loop until 1 of 2 variables meets the criteria of the while statement. So when either intWidth or intHeight drops below either MaxWidth or MaxHeight respectively the loop will end.

Right now when I run this, the loop continues until both intWidth and intHeight are below MaxWidth and MaxHeight.

                    intHeight = (int)Math.Round(MaxHeight * varRatio, 0);
                    intWidth = (int)Math.Round(MaxWidth * varRatio, 0);
                } while (intWidth > MaxWidth || intHeight > MaxHeight);

Any help would be great


Avatar of gregoryyoung
Flag of Canada image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RubenvdLinden

Gregory is right.

|| is an OR operator. If one of the variables meets the criteria of the statement, the loop will continue.
&& is an AND operator. The loop will continue as long as both of the variables meet the criteria. If one of both variables drops below the MaxWidth or MaxHeight, the criteria is no longer met and the loop will end.