# if (x && y || z)

• 05-15-2003
Noobie
if (x && y || z)
if I have something like

'm'==command[0] && 'u'==command[1] || 's'==command[2]

how does it work? Can I use both && and || together and if so what does it mean? Does it mean (this AND that) OR that or this (AND that OR that)
• 05-15-2003
quzah
Sure you can use it. You just have to pay attention to presidence, or do the smart thing and use parenthesis to state exactly what you mean.

Quzah.
• 05-15-2003
Munkey01
if (com[0] == 'm' || (com[1] == 'n' && com[2] == 'o'))

If com[0] equals 'm' or if com[1] equals 'n' and com[2] equals 'o,' then do what ever.
• 05-15-2003
Trauts
I think he might mean would it be equivilent to this:

( ('m'==command[0] && 'u'==command[1]) || ('m'==command[0] && 's'==command[2]) )

In which case, no.
• 05-15-2003
major_small
just remember to use parenthesis when you're using both '&&' and '||'
Code:

```( XX && YY || ZZ ) // TRUE IF: // XX AND YY // OR: // ZZ ( ( XX && YY ) || ZZ ) // TRUE IF: // XX AND YY // OR: // ZZ ( XX && ( YY || ZZ)) // TRUE IF: // XX // AND: // YY OR ZZ```
a great example of how parentesis make a big difference...
• 05-15-2003
Noobie

Code:

`if (!strcmpi("execute command", command))`
is there a way to check and see if command includes "execute command" without checking to see that command[0]=e and command [1]=x and so on...or perhaps to check that command[0-14]='execute command' ?
• 05-16-2003
nvoigt
Use the strstr function. It should be in your reference.
• 05-16-2003
Noobie
I don't know what a reference is, aside from a dictionary or encyclopedia.
• 05-16-2003
Munkey01
A nice reference is http://www.cppreference.com/

The specific page for strstr() is here, http://www.cppreference.com/com/stds...ls.html#strstr
• 05-17-2003
Noobie
I have no idea what this means
Code:

``` #include <string.h>   char *strstr( const char *str1, const char *str2 ); The function strstr() returns a pointer to the first occurrence of str2 in str1, or NULL if no match is found.```
• 05-17-2003
JasonD
You have to know what pointers are to understand that. The function simply finds the first occurrence of a substring within a larger string. Instead of returning an index to its find, it returns a pointer to it.