How to define conditional function with Mathematica?

I think it's easier just to define this straight up, rather than compute something procedurally.

f[1, 0] = 77;
f[0, 1] = 66;
f[_, _] = 0;

Mathematica is fundamentally an expression rewriting system, so telling it how to rewrite expressions directly like this is usually clearer, faster, and easier to debug.


f[x_Integer, y_Integer] :=Which[x == 1 && y == 0, 77, x == 0 && y == 1, 66, True, 0]

The null represents "all other values". You can replace it with anything you like.

f[x_, y_] := If[x == 1 && y == 0, 77, If[x == 0 && y == 1, 66, If[IntegerQ[x] && IntegerQ[y], 0, null]]]

Test it:

f[1, 0]

OUT: 77

f[0, 1]

OUT: 66

f[9, -2]

OUT: 0

f[9, 1.1]

OUT: null

f[1.2, Pi]

OUT: null