previous | start | next

C++ Statements

C++ statements are typically terminated by a semicolon. A sequence of statements may, however, be enclosed in {} and treated as a single compound statement.

C++ has a small number of statement types:

Expression (Just an expression alone as a statement.)
x + y;
f(x);  // call a function f, passing a value x
     
(Most languages similar to C++ don't allow expressions by themselves as statements.)
Assignment statement
z = x + y;
The left side of an assignment statement must be (or evaluate) to a variable. The right side must be an expression whose type is compatible with the type of the left side.
Flow of control statements
         if statements: Select one of two choices based
          on a boolean expression
         
         loop statements: for, while,
          do loops. Repeat a sequence of statements depending
          on the value of a boolean expression.
         
         switch statements: Select one of many choices
          depending on the value of an integer or character expression.
      


previous | start | next