Avatar of sneeri_c
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.

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

Any help would be great

Thanks

     
C#

Avatar of undefined
Last Comment
RubenvdLinden

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
gregoryyoung

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
Your help has saved me hundreds of hours of internet surfing.
fblack61