in reply to What is the difference between a Statement and an Expression?
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.
In the next example the first statement will work but the second will not.if ($foo) { print "True\n" } else { print "False\n" } $foo ? print "True\n" : print "False\n"
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: What is the difference between a Statement and an Expression?
by premchai21 (Curate) on Aug 03, 2001 at 09:55 UTC | |
Re^2: What is the difference between a Statement and an Expression?
by JavaFan (Canon) on Mar 02, 2012 at 01:20 UTC |