< previous page page_235 next page >

Page 235
The computer is a very literal deviceit does exactly what we tell it to do, which may or may not be what we want it to do. We try to make sure that a program does what we want by tracing the execution of the statements.
We use a nonsense program below to demonstrate the technique. We keep track of the values of the program variables on the right-hand side. Variables with undefined values are indicated with a dash. When a variable is assigned a value, that value is listed in the appropriate column.
Value of
Statement
a
b
c
const int x = 5;
int main()
{
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
int a, b, c;
-
-
-
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b = l;
-
1
-
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c = x + b;
-
1
6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a = x + 4;
9
1
6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a = c;
6
1
6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b = c;
6
6
6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a = a + b + c;
18
6
6
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c = c % x;
18
6
1
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c = c * a;
18
6
18
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a = a % b;
0
6
18
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
cout << a < b < c;
0
6
18
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
return 0;
0
6
18
}

Now that you've seen how the technique works, let's apply it to the LumberYard program. We list just the executable statement portion here, modified to reflect the results of our algorithm walk-through.

 
< previous page page_235 next page >