A fairly simple question...
Displaying 1-10 of 10 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Nexys

How do I designate an "OR" condition in my if() statements?

Thanks in advance.

Posted on 2004-08-05 02:05:19

Ness

Use the boolean or operator ||


if(1==1 || 2==2)
{
log("Logic is holding true");
}
else
{
log("We don't exists in reality anymore");
}

Posted on 2004-08-05 02:18:39

athocreft

Don't do this:

if( (1==1) || (2==2) ) {}

For some reason it wigs out for me when I used ()'s around the conditions. Just a heads up.

Posted on 2004-08-06 08:26:34

mcgrue

Also, and just for clarity. Say you wanted to check if a variable was either 1 or 2. Do not be tricked by how it's said out loud, because computers don't speak english.

bad and wrong:



if( my_var == 1 || 2 ) {
log( "this is wrong!" );
}


That statement is wrong because it's making two checks:

  • is (my_var == 1) true?
  • is (2) true?


Since 2 is always true (in verge, like C, only the number 0 is false), that if-statement will alwys execute, regardless of whether my_var is 1 or 2.

The following is how to properly write that statement:

good and strong:



if( my_var == 1 || my_var == 2 ) {
log( "my_var is either equal to 1 or 2!!!" );
}


Now you know. And knowing is half the battle :)

Posted on 2004-08-06 09:16:00

Interference22

Quote:Originally posted by mcgrue

Now you know. And knowing is half the battle :)


...And understanding is the other half, right?

Posted on 2004-08-06 23:35:53

blues_zodiakos

I don't think you have to use ==. You can use just = too if you want.

Posted on 2004-08-06 23:45:51

mcgrue

Quote:Originally posted by Interference22

Quote:Originally posted by mcgrue

Now you know. And knowing is half the battle :)


...And understanding is the other half, right?


I think the other half is actually having superior firepower.

Quote:Originally posted by Blues Zodiakos

I don't think you have to use ==. You can use just = too if you want.


Yeah, but it's better form to use ==, just for the habit.

Posted on 2004-08-06 23:49:45

Zip

Quote:Originally posted by mcgrue

Quote:Originally posted by Interference22

Quote:Originally posted by mcgrue

Now you know. And knowing is half the battle :)


...And understanding is the other half, right?


I think the other half is actually having superior firepower.



I thought the other half was understanding the other half. ;)

Zip

[PS. But yeah, always use == or you will die in later life.]

Posted on 2004-08-07 01:16:33

mcgrue

Understanding that the other half knows that the other half of the battle is to have superior firepower is the other half of the battle for your half, if your half doesn't have the superior firepower.

Posted on 2004-08-07 01:42:04

zaril

Knowing half the battle means you're not drunk enough.

Posted on 2004-08-10 00:08:23


Displaying 1-10 of 10 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.