A92: Re: C -- Boolean logic?
[Prev][Next][Index][Thread]
A92: Re: C -- Boolean logic?
> is there a way to do boolean logic in C?
> so that instead of doing this:
>
> if(a = 5)
> {
> if(b = 10)
> {
> do this code
> }
> }
"do this code" would *always* be executed here, because you use a single "="
sign, which in C is used for setting a variable to something. And since 5 <>0
and 10 <>0 (0 = FALSE)...
>
> l can do this:
>
> if(a = 5 AND b = 10)
> {
> do this code
> }
>
> However, it doesn't work. Any way to do it?
Easy:
if((a == 5) && (b == 10))
{
do this code
}
(Notice the double "=" signs)
I would suggest reading a tutorial or something about C in general, since there
are many of these small things that can easily be confusing if you don't know
about them. A good reference point for gcc is
http://www.delorie.com/gnu/docs/gcc
And Yahoo has a fairly good set of links to C tutorials.
/ Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF Quote follows:
Dhblah sidled closer. This was not hard. Dhblah sidled everywhere. *Crabs*
thought he walked sideways.
-- (Terry Pratchett, Small Gods)
References: