if, else if, else with or (||) should this work?
Posted: Tue Nov 17, 2015 7:37 pm
Hi, I can't get this bit of code to pass the first "if" check (it always returns nZone = 17), what am I doing wrong?
I've got round by using
Which is fine for this appilcation. But thought it should have worked.
Thanks for looking.
Code: Select all
rLen = (random(6)); // random number 0->5
if (rLen == 0 || 1 || 2 ){ // if equal to 0, 1 or 2
nZone = 17; // nZone = 17, if == 0, 1 or 2
}
else if (rLen == 3 || 4){ // if equal to 3 or 4
nZone = 16; // nZone = 16, if == 3 or 4
}
else {
nZone = 15; // nZone = 15, if == 5 (or none of the above)
{
I've got round by using
Code: Select all
rLen = (random(6));
if (rLen < 3 ){
nZone = 17;
}
else if (rLen <5){
nZone = 16;
}
else {
nZone - 15;
{
Which is fine for this appilcation. But thought it should have worked.
Thanks for looking.