15.6 If

15.6.1 Synopsis

The simplest form of if statement is:

if (condition)
  statement;

A slightly more complex form is:

if (condition)
  statement;
else
  alternate_statement;

while the more complete form is:

if (condition)
  statement;
elif condition_2)
  statement_2;

[ ... ]

elif condition_n)
  statement_n;
else
  default_statement;

15.6.2 Description

With the former syntax, if condition evaluates to true Cows will execute the statement. With the second syntax, if condition evaluates to true Cows will execute the statement; otherwise, it will execute the alternate statement.

Finally, the last syntax allows to choose among an arbitrary number of cases. Conditions are checked top to bottom; when a condition is true the corresponding statement is executed and following clauses are skipped. If no condition is true, the else statement (if present) is executed.

You can also execute more than one statement under a certain condition: simply enclose them between braces:

if (condition) {
  statement;
  statement;
} else {
  alternate statement;
  alternate statement;
}

Remember that whitespaces don't affect Cows' behavior so the following forms are misleading:

if (foo == "something")
  print (x); print (y);
if (foo == "something")
  print (x);
  print (y);

Both forms suggest that x and y are printed only if foo equals something but Cows doesn't care about formatting so they are equivalent to:

if (foo == "something")
  print (x);
print (y);

y is printed anyway, regardless to foo but that's not what you probably wanted; correct ways to write the code above are:

if (foo == "something") {
  print (x); print (y);
}
if (foo == "something") {
  print (x);
  print (y);
}

The second form is much more readable.

15.6.3 Example

if (some_variable == "Cows") {
  print ("You're thinking I'm one of those wise-ass California");
  print ("vegetarians who is going to tell you that eating a few");
  print ("strips of bacon is bad for your health. I'm not. I say");
  print ("it's a free country and you should be able to kill yourself");
  print ("at any rate you choose, as long as your cold dead body is");
  print ("not blocking my driveway.");
  print ("-- Scott Adams (writer of Dilbert)");
}

If some_variable equals to Cows Cows' output will be:

You're thinking I'm one of those wise-ass California
vegetarians who is going to tell you that eating a few
strips of bacon is bad for your health. I'm not. I say
it's a free country and you should be able to kill yourself
at any rate you choose, as long as your cold dead body is
not blocking my driveway.
-- Scott Adams (writer of Dilbert)

Otherwise, there will be no output.

15.6.4 Example (2)

if (some_variable_1 != some_variable_2) {
  print ("I don't understand why asking people to eat a");
  print ("well-balanced vegetarian diet is considered drastic,");
  print ("while it is medically conservative to cut people open");
  print ("and put them on cholesterol-lowering drugs for the rest");
  print ("of their lives.");
  print ("-- Dean Ornish, MD");
} else {
  print ("When we kill the animals to eat them, they end up");
  print ("killing us because their flesh, which contains cholesterol");
  print ("and saturated fat, was never intended for human beings.");
  print ("-- William C. Roberts, M.D.,");
  print ("editor of The American Journal of Cardiology");
}

If some_variable_1 and some_variable_2 differ Cows' output will be:

I don't understand why asking people to eat a
well-balanced vegetarian diet is considered drastic,
while it is medically conservative to cut people open
and put them on cholesterol-lowering drugs for the rest
of their lives.
-- Dean Ornish, MD

Otherwise, if some_variable_1 equals to some_variable_2 Cows' output will be:

When we kill the animals to eat them, they end up
killing us because their flesh, which contains cholesterol
and saturated fat, was never intended for human beings.
-- William C. Roberts, M.D.,
editor of The American Journal of Cardiology

15.6.5 Example (3)

if (version == "standard") {
  // Standard version
  print ("To be a vegetarian is to disagree -- to disagree with");
  print ("the course of things today. Starvation, world hunger,");
  print ("cruelty, waste, wars -- we must make a statement against");
  print ("these things. Vegetarianism is my statement. And I think");
  print ("it's a strong one.");
  print ("-- Isaac Bashevis Singer");
} elif (version == "no_frames") {
  // No frames version
  print ("It seems disingenuous for the intellectual elite of");
  print ("the first world to dwell on the subject of too many");
  print ("babies being born in the second- and third-world");
  print ("nations while virtually ignoring the over-population of");
  print ("cattle and the realities of a food chain that robs the");
  print ("poor of sustenance to feed the rich a steady diet of");
  print ("grain-fed meat.");
  print ("-- Jeremy Rifkin");
} elif (version == "fully_accessible") {
  // Fully accessible version
  print ("The fact is that there is enough food in the world");
  print ("for everyone. But tragically, much of the world's");
  print ("food and land resources are tied up in producing beef");
  print ("and other livestock--food for the well off--while");
  print ("millions of children and adults suffer from malnutrition");
  print ("and starvation.");
  print ("-- Dr. Walden Bello");
} else {
  // Unknown version ... use default
  print ("Our food system takes abundant grain, which people");
  print ("can't afford, and shrinks it into meat, which better-off");
  print ("people will pay for.");
  print ("-- Frances Moore Lappe");
}

If version equals to standard Cows' output will be:

To be a vegetarian is to disagree -- to disagree with
the course of things today. Starvation, world hunger,
cruelty, waste, wars---we must make a statement against
these things. Vegetarianism is my statement. And I think
it's a strong one.
-- Isaac Bashevis Singer

If version equals to no_frames Cows' output will be:

It seems disingenuous for the intellectual elite of
the first world to dwell on the subject of too many
babies being born in the second- and third-world
nations while virtually ignoring the over-population of
cattle and the realities of a food chain that robs the
poor of sustenance to feed the rich a steady diet of
grain-fed meat.
-- Jeremy Rifkin

If version equals to fully_accessible Cows' output will be:

The fact is that there is enough food in the world
for everyone. But tragically, much of the world's
food and land resources are tied up in producing beef
and other livestock--food for the well off--while
millions of children and adults suffer from malnutrition
and starvation.
-- Dr. Walden Bello

In every other case Cows' output will be:

Our food system takes abundant grain, which people
can't afford, and shrinks it into meat, which better-off
people will pay for.
-- Frances Moore Lappe

This manual can be downloaded from http://www.g-cows.org/.