Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Understanding Statements and Expressions
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sun Oct 31, 2004 10:02 pm   Post subject: Understanding Statements and Expressions

Two of the most frequently confused terms in programming are statement and expression.

A statement in a program is code which doesn't have any value on its own. In Turing, consider:

code:
var hw : string := "Hello world"


This does something, but it can't be used as a value.

An expression has a value of its own. In an ideal world it wouldn't actually do anything to the rest of the world, but very few languages enforce that. Consider:

code:
var hw : string := "Hello " + "world"


All together this isn't an expression, but rather a statement. However:

code:
"Hello " + "world"


Is an expression. It doesn't modify either "Hello " or "world", but it creates something new and returns it.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: