Tinkering with Perl

Jonathan's Corner (Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  34  35  36  37  38  39  40  41  42  43  Next  Skip Forward
Printer-Friendly Version

If-then-else

Suppose that I want to do something in a programming language. Some pseudocode might be as follows:

if (I know how to do it)
    {
    do it;
    }
else
    {
    try to find out how to do it;
    }

There is one thing I want to do if the conditional clause is true, and another thing to do if the conditional clause is false. And that is done with this exact syntax:

if (conditional clause)
    {
    block of code to execute if the conditional clause is true
    }
else
    {
    block of code to execute if the conditional clause is false
    }

See also:

Statements - Arithmetic - Flow control - Blocks - Conditional clauses - If-then - If-then-else chains

Tinkering with Perl is a free book that provides an introduction to programming in Perl, as well as a basic reference for things like foreach in Perl, if-then, and if-then-else, in addition to providing a glossary where you can find definitions for concatenate and other terms.

Tinkering with Perl may be one of the most popular offerings on this site, but it's not the only attraction. You can read a tongue-in-cheek Game Review: Meatspace, read an even more offbeat customer service survey (whether or not you actually fill it out), and spend a few minutes wishing your boss would read, The Administrator Who Cried, "Important!" (Not to mention that there are other things you can read here besides tech stuff, from Janra Ball: The Headache to The Spectacles.)

Read more...

Top

Jonathan's Corner (Search & Sitemap) > Writing > Miscellaneous Nonfiction > Tinkering with Perl
Skip Back  Previous  34  35  36  37  38  39  40  41  42  43  Next  Skip Forward
Printer-Friendly Version