0% found this document useful (0 votes)
42 views16 pages

Plant Sim For Loop

This document summarizes debugging steps for a bug in a for loop where the loop variables i and j are getting switched. The debugging shows that on each iteration i is being incremented instead of j, causing the incorrect values to be displayed. Adding an exit condition to the loop fixes the bug by stopping iteration when i equals 2, but it incorrectly displays i outside the loop as if it were j.

Uploaded by

dannystrad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views16 pages

Plant Sim For Loop

This document summarizes debugging steps for a bug in a for loop where the loop variables i and j are getting switched. The debugging shows that on each iteration i is being incremented instead of j, causing the incorrect values to be displayed. Adding an exit condition to the loop fixes the bug by stopping iteration when i equals 2, but it incorrectly displays i outside the loop as if it were j.

Uploaded by

dannystrad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Plant Simulation

For loop variables bug


Code

Bug is here

Table
“Should be” values of i and j loop variable Output of the code for i and j loop variable
Debug - step 1

i=2
Next step should be:
i=2
j=1
Debug - step 2

i should be 2, In the table, the values are


instead: copied wrong. But they are
i=1 correct as if there’s no the
j=2 variables switch.
Debug - step 3

i is incremented instead of j
Debug - step 4

i returns to its correct value


Debug - step 5

Again

i should be 3, In the table, the values are


instead: copied wrong. But they are
i=1 correct as if there’s no the
j=3 varaibles switch.
Debug - step 6

Again

In the table, the values are


i is
copied wrong. But they are
incremented
correct as if there’s no the
instead of j
variables switch.
Debug - step 7

Again

In the table, the values are


i is
copied wrong. But they are
incremented
correct as if there’s no the
instead of j
variables switch.
Code with exitloop

Bug is here
Debug with exitloop - step 1

i should be 2, But the condition i = 2 is


instead: satisfied (see next page)
i=1
j=2
Debug with exitloop - step 2

i should be 2, Condition satisfied


instead:
i=1
j=2
Debug with exitloop - step 3

i should be 3, instead it has been dumped as if


it was j outside the loop (see next page)
Debug with exitloop - step 4

i should be 3, instead it has been dumped as if


it was j outside the loop (see next page)
Debug with exitloop - step 5

i should be 3, instead it has been dumped as if


it was j outside the loop
Debug with exitloop - step n

Error if you don’t interrupt the code with the


messageBox. j still exists but not i.

You might also like