 Welcome to the course on computer programming and to the session on code blocks. In this session, we will see how to debug our programs using this ID. We want to write a program that accepts a number from the user and prints its tables. To use the debugging feature, we need to create a project and not a file. Assuming that the project multiply numbers is already created, we shall start writing the program. hash include iostream using namespace std int main return 0. This is our template code. We will now declare a number number 1, a variable counter equals to 1 and the answer that we need to compute. See out, enter a number which will be printed on the screen, semicolon seen number 1. The number will be accepted from the user. Now we will write our logic of the program to print the tables. So our logic would be using a while loop, while counter is less than equal to 10, open curly presses answer equal to num1 into counter and we will print the answer as see out num1 into counter equal to answer. In short, num1 is the number entered by the user into the variable counter equals to the answer which is computed by multiplying num1 and counter. That is it. This is our program. I feel that this is the correct program and we should now execute it. So we will save it and we will click on build and run. The terminal has appeared. We will enter a number say 6 and we will press enter. Let us see what the output of the program is. Oh my God, 6 into 1 equal to 6 is getting printed infinitely. I thought my program was correct. Well, I think I need to use the debug feature of code blocks. So let us close this. So for debugging, we require a watch window is nothing but a window that will display the values of all variables step by step as the program executes. Watch window can be enabled from debug, debugging windows and watches. As soon as you click the watches window appears, we will fix it below over here. We are now ready to debug a program. Let us go to the first statement where int num1, counter equal to 1 and answer is declared as integer. We will click on debug and run to cursor. We will now adjust our code blocks window so that we can have a terminal window side by side. As you can see, enter a number is not displayed on the terminal. The reason is run to the cursor means that it will come to this line and it will halt. Note this yellow triangle. Now in debugging mode, every time you want to execute a statement, code blocks ID will wait for the user that means the programmer to press shift F7 that is to go to the next line. We will click over here and we will press shift F7 on our keyboard. Notice the cursor has advanced over here to see out enter a number. Please note till now the statement enter a number is not displayed. The reason is it has executed this statement but it has still not executed enter a number statement. Now, when we will press shift F7, please note that the enter a number will be displayed shift F7. Enter a number is displayed. Then we will press shift F7 so that we can enter a number over here. Say for example, 6 as we mentioned earlier and we will press enter. Now the control has come back again to our program which is while counter is less than equal to 10. The value of counter over here can be seen number 1 equal to 6 which we have entered counter equal to 1 which we have declared earlier. Answer equal to some garbage value is displayed. Now since the value of counter is definitely less than equal to 10, when we press shift F7 the control will go inside the loop. Shift F7 answer equal to num1 into counter will be executed. Now note that answer equal to 6 has been calculated. This statement c out num1 into counter equal to answer that is I believe it should be 6 into 1 equal to 6 will be displayed when we again press shift F7. Yes, 6 into 1 equal to 6 has been displayed. Now the control has gone back to the while loop where it checks counter is less than equal to 10. Now, let us see what is the value of counter. Oh counter value is still 1. Now so that means it will go inside the while loop again. Shift F7 answer will be calculated as 6 the statement c out num1 equal to counter is equal to answer will be printed that is 6 into 1 is 6 and now this goes into infinite loop as I press my shift plus F7. I now realize my mistake that counter variable is not incremented. If I increment my counter variable here it will appear as 2, 3, 4, 5, 6, till 10. So let us exit this and modify our program. We will add a statement after the c out statement counter equal to counter plus 1. Yes, I believe now that should solve my problem but still instead of executing the program directly I will still want to go through the debug. I will now come over here to int num1 statement and click debug, run to cursor. I place my terminal over here on the right hand side. Now I will press shift F7, shift F7 enter a number as displayed I will press shift F7 again so that I am allowed to enter a number I will enter number 6 and I will press enter. I will again come here oops I forgot to add the watch window. So I will click here debugging windows which is also a shortcut and I will say watches. I will add this here and click on local variables. Please note my num1 has value 6, counter equal to 1. Now over here while counter is less than equal to 10, yes the value of counter is 1 which is definitely less than equal to 10. So my control enters the while loop I will press shift F7, answer equal to num1 into counter will be executed now, shift F7 please note the answer is 6 which will now be printed over here, shift F7 6 into 1 equal to 6. Now the counter equals to counter plus 1 will be executed when I press shift F7, yes the counter value has incremented to 2. Now while counter that is 2 is less than equal to 10, yes it is so it will enter the loop answer equal to num1 into counter will be executed which is nothing but 12. This statement is printed over here as 6 into 2 equal to 12. Counter value is incremented to 3 again control goes into the loop I will now continuously press shift F7, answer is getting computed which is printed on the terminal counter value is incremented to 4, I will execute this 6 into 5, 30, 6 into 6, 36, 6 into 7, 42, 6 into 8, 48, 6 into 9, 54 please note the value of counter is 9. Now on pressing shift F7 the value of counter is incremented to 10, still the control will enter into the while loop because the while loop condition is satisfied wherein 10 is definitely equal to 10. So my answer will be calculated again which is 60, the answer will be printed over here 6 into 10, 60. Now my counter variable is incremented to 11, at this point while counter is less than equal to 10 is not satisfied. So the control will now go to return 0 instead of going inside the while loop. I will press shift F7 to see the result, F7 yes it has gone outside the while loop which is written 0, shift F7 to exit which says now no locals over here. This is how we debug our programs. Using this debug feature we were able to examine the value of our variables at every step and could hence identify the flaw in our program. Of course this was a very small program and may be would be very easy to identify without using debug, but imagine that the program was 2000 lines, 2 million lines in such cases it would be very difficult to do so. Hence code blocks ID provides us with this debugging feature. We end this session and hope the debugging feature will help you debug and solve the errors in your programs. Thank you.