From 65677d017143e7639d1c35908894eb0af4929d30 Mon Sep 17 00:00:00 2001 From: Andrei F Date: Wed, 12 Oct 2022 22:18:58 -0700 Subject: Finished exercise 1-2 --- CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp') diff --git a/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp b/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp index 0dce1cd..b0552a7 100644 --- a/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp +++ b/CST116-Ch8-Debugging/CST116-Ch8-Debugging.cpp @@ -16,9 +16,17 @@ * 6) Step over the cout statement. * 7) Why didn't the flow of the program return back to the while * statement? + * + * The flow of the program did not return to the while statement because of the semicolon on the while statement, + * this is also explained in the next step. The brackets, which I thought had an error to do with the + * flow of the program not returning to the while statement do not matter here. + * * 8) Fix this problem by removing the ; after the while statement. * 9) Stop debugging and repeat Steps 2 � 5 to verify the correction * worked. + * + * Done, however, debugging will now not enter the while block to execute the cout statement. + * * 10) Stop debugging. * * Debugging Exercise 2 @@ -26,11 +34,19 @@ * 1) Run to Breakpoint 1. * 2) Step into the while loop. * 3) Why did the cout not execute? + * + * The cout did not execute because the while loop is comparing if the variable i is less than 0. + * However, the variable i is initialized as 0, and therefore is not less than 0, so it does not step + * into the while loop. + * * 4) Check the value of i, now check the condition, does the * condition evaluate to true? * 5) Change the "< 0" to a "< 10". * 6) Stop debugging and repeat Steps 1 � 4 to verify the correction * worked. + * + * It works but it's an infinite loop. + * * 7) Stop debugging. * * Debugging Exercise 3 @@ -59,14 +75,15 @@ using std::endl; int main() { - int i = 0; + int i = -1; int count; // Breakpoint 1 // Put a breakpoint on the following line - while (i < 0); + while (i < 0) cout << i << endl; + // Breakpoint 2 // Put a breakpoint on the following line for (count = 0; count < 10; count++); -- cgit v1.2.3