From: nt on
Hi all,

Is there a way to build an if statement with two conditions such as:
if[a>b and a>0,...]. If there is, could you let me know the syntax?

Thanks
nt

From: Bob Hanlon on

f[x_, y_] := If[x > y && Mod[x, 2] == 0, 1, 0]

g[x_, y_] := If[And[x > y, Mod[x, 2] == 0], 1, 0]

mat = Table[{x, y}, {x, 0, 4}, {y, 0, 4}];

Apply[f, mat, {2}]

{{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
{1, 1, 0, 0, 0}, {0, 0, 0, 0, 0},
{1, 1, 1, 1, 0}}

% == Apply[g, mat, {2}]

True


Bob Hanlon

---- nt <sagittarius5962(a)gmail.com> wrote:

=============
Hi all,

Is there a way to build an if statement with two conditions such as:
if[a>b and a>0,...]. If there is, could you let me know the syntax?

Thanks
nt



From: Nasser M. Abbasi on

"nt" <sagittarius5962(a)gmail.com> wrote in message
news:hosi59$o49$1(a)smc.vnet.net...
> Hi all,
>
> Is there a way to build an if statement with two conditions such as:
> if[a>b and a>0,...]. If there is, could you let me know the syntax?
>
> Thanks
> nt
>


a = 3;
b = 2;
If[a > b && a > 0, Print["correct"], Print["try again"]]

or

a = 3;
b = 2;
If[And[a > b, a > 0], Print["correct"], Print["try again"]]

?If

--Nasser



From: David on
On Mar 30, 1:01 pm, nt <sagittarius5...(a)gmail.com> wrote:
> Hi all,
>
> Is there a way to build an if statement with two conditions such as:
> if[a>b and a>0,...]. If there is, could you let me know the syntax?
>
> Thanks
> nt

Hello

I believe this is what you're looking for:

If[ a>b && a>0 , ... ]
or in FullForm:
If[ And[a>b, a>0] , ... ]

From: DrMajorBob on
Look up "And" or "&&".

Bobby

On Tue, 30 Mar 2010 05:01:24 -0500, nt <sagittarius5962(a)gmail.com> wrote:

> Hi all,
>
> Is there a way to build an if statement with two conditions such as:
> if[a>b and a>0,...]. If there is, could you let me know the syntax?
>
> Thanks
> nt
>


--
DrMajorBob(a)yahoo.com