Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 207

# c# for and if loops using multi constarnts in argumant

What is the correct way to write the below equations were i need a corridor between 2 values
between for examp 10 and 100 but only if it falls between there
if ( a >= 10 and a <= 100)
{

}

while ( a < 10 and a < 100)
{

}
0
sydneyguy
• 4
• 2
1 Solution

Billing EngineerCommented:

the second statement (while) is logically wrong because it used < and < for both ...
apart from that >= and <= will include the values for testing , so a >= 10 will return true for a being 10, with a > 10 it will return false ...
0

Author Commented:
i only want to equation to enter or to stay in side if the number is
>= 10 and the number is <= 100 so any number between 10 and 100 will fire off the equation
0

Author Commented:
sorry
while ( a < 10 and a < 100)
{

}
it should be
hile ( a > 10 and a < 100)
{

}
0

Billing EngineerCommented:
I thought so :)

anyhow, what is the problem, then?
0

Author Commented:
i only want to equation to enter or to stay in side if the number is
>= 10 and the number is <= 100 so any number between 10 and 100 will fire off the equation

so i would like the for loop to keep processing until a goes out side in this example changes to < 10 or goes over the 100 but would like to do it in one line
in excel it woudl be simply  if ( 1 > 10 and a < 100 ) it would fall into the statement and do it
thats it in a nut shell
thanks for the help so far
0

Commented:
while(10 <= a && a <= 100)
{
a = GetNewValue();
}
0

Author Commented:
i tried the && and it threw up errors but redoing it with you rcode it ran, muist have had something else defined wrong
but i though this is what was required
thanks for the second set of eyes
0

## Featured Post

• 4
• 2
Tackle projects and never again get stuck behind a technical roadblock.