Outline:


Variable errors:

Problem Type Comments
Undeclared Compiler
Error
Variable not declared, examples of declarations:
int a; float b; double c; char d; boolean e;
Unreferenced Compiler
Warning
Variable not used in the code, examples of use:
x = y + z; // x, y and z are now referenced
Uninitialized Runtime
Error

Variable not given a specific value before it is used in a RHS (right hand side) expression.

Variables can be initialized in 3 ways:

  1. As part of their declaration            example: int n = 5;
  2. As the LHS of an assignment statement   example: n = a + b * 3;
  3. Using an Input statement                example: cin >> n;

 


For loops


Pseudo-code
In C/C++/Java:
Flow chart

General syntax:
Code
Flow chart



Venit, pg 237, Problem 4.37


Pseudo-code

Output

Tracing the code,
just after the
write statement:

Without comments:

4
5
8
10
12
15

I J Output
1 4 4
1 5 5
2 4 8
2 5 10
3 4 12
3 5 15

With comments

Pseudo-code

Equivalent C++ code

Updated: Nov 4, 2008
Copyright: Nicholas Duchon