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
  • Last Modified:

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
Asked:
sydneyguy
  • 4
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
why do you ask, actually?

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
 
sydneyguyAuthor 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
 
sydneyguyAuthor Commented:
sorry
while ( a < 10 and a < 100)
{

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

}
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I thought so :)

anyhow, what is the problem, then?
0
 
sydneyguyAuthor 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
 
strickddCommented:
while(10 <= a && a <= 100)
{
     a = GetNewValue();
}
0
 
sydneyguyAuthor 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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