Don't try to read too much into the difference beween a statement and an expression.

The main point to remember is that an expression can be used inside a statement, or another expression. You can have a subexpression, but there is not such thing as a "sub-statement".

The distinction between statement and expression is just an artifact of the language. Some languages only have expressions (LISP), and others only have statements (assembly).

Look at the following example. Both do the same thing, but the first is a statement and the other an expression.

if ($foo) { print "True\n" } else { print "False\n" } $foo ? print "True\n" : print "False\n"
In the next example the first statement will work but the second will not.
print $foo ? "True\n" : "False\n"; print if ($foo) { "True\n" } else {"False\n"};

Why not? Mostly just because C is that way. If your not confused, notice that what I called an expression in the first example, is now a statement becuase there is a semicolon at the end. It is a subtle bit of terminology that really isn't a big deal.


In reply to Re: What is the difference between a Statement and an Expression? by inverse
in thread What is the difference between a Statement and an Expression? by supernewbie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.