• Create Account

Banner advertising on our site currently available from just \$5!

### #Actualaregee

Posted 22 February 2014 - 09:45 AM

Vortez solution is the way to go, but it seems you have a flaw in your logic:

    if(i < 10) //This will be run if i is less than 10
if(i > 10 || i < 20) //This will be run regardless
if(i > 20 || i < 30) //This will be run regardless


What you have written is exactly the same as:

    if(i < 10) //This will be run if i is less than 10
if(true) //This will be run regardless
if(true) //This will be run regardless


I think this is what you meant:

    if(i < 10) //This will be run if i is less than 10
if(i >= 10 && i < 20) //This will be run if i is greater or equal to 10, but less than 20
if(i >= 20 && i < 30) //This will be run if i is greater or equal to 20, but less than 30


EDIT: Although operator precedence ensures the correct order of operation in this case, I usually wrap the tests like this for ease of reading:

    if ((i >= 20) && (i < 30))

But that is probably just taste...

### #3aregee

Posted 22 February 2014 - 09:43 AM

Vortez solution is the way to go, but it seems you have a flaw in your logic:

    if(i < 10) //This will be run if i is less than 10
if(i > 10 || i < 20) //This will be run regardless
if(i > 20 || i < 30) //This will be run regardless


What you have written is exactly the same as:

    if(i < 10) //This will be run it i is less than 10
if(true) //This will be run regardless
if(true) //This will be run regardless


I think this is what you meant:

    if(i < 10) //This will be run it i is less than 10
if(i >= 10 && i < 20) //This will be run if i is greater or equal to 10, but less than 20
if(i >= 20 && i < 30) //This will be run if i is greater or equal to 20, but less than 30


EDIT: Although operator precedence ensures the correct order of operation in this case, I usually wrap the tests like this for ease of reading:

    if ((i >= 20) && (i < 30))

But that is probably just taste...

### #2aregee

Posted 22 February 2014 - 09:38 AM

Vortez solution is the way to go, but it seems you have a flaw in your logic:

    if(i < 10) //This will be run if i is less than 10
if(i > 10 || i < 20) //This will be run regardless
if(i > 20 || i < 30) //This will be run regardless


What you have written is exactly the same as:

    if(i < 10) //This will be run it i is less than 10
if(true) //This will be run regardless
if(true) //This will be run regardless


I think this is what you meant:

    if(i < 10) //This will be run it i is less than 10
if(i >= 10 && i < 20) //This will be run if i is greater or equal to 10, but less than 20
if(i >= 20 && i < 30) //This will be run if i is greater or equal to 20, but less than 30


### #1aregee

Posted 22 February 2014 - 09:36 AM

Vortez solution is the way to go, but it seems you have a flaw in your logic:

	if(i < 10) //This will be run it i is less than 10
if(i > 10 || i < 20)  //This will be run regardless
if(i > 20 || i < 30)  //This will be run regardless


What you have written is exactly the same as:

    if(i < 10) //This will be run it i is less than 10
if(true) //This will be run regardless
if(true) //This will be run regardless


I think this is what you meant:

    if(i < 10) //This will be run it i is less than 10
if(i > 10 && i < 20) //This will be run regardless
if(i > 20 && i < 30) //This will be run regardless


PARTNERS