For Next Trace Table 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

NUMBER & FULL NAME:________________________________________________

Computer Science (Visual Basic) CODE REVIEW ForNextTraceTable2

This program uses a FOR NEXT loop to add the numbers 0, 1, 2 and 3.

1 Name one important comment that is missing from this program. [1]
Name of programmer, Date/Time, Program description, Textbook page number, ...
..............................................................................................................................................................................................................

2 Where is a good place to declare the variables in a program and explain why? [2]
At the start of the program, easy to locate to check and/or to modify, less likely to create a duplicate,
..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

3 Carefully list the details of variable(s) in this program: [2]

ForNextTraceTable2

Line Number Variable Identifier Data Type


5 Index Integer
6 Total Integer
4 List 4 data types available in Visual Basic [4]
Integer, Boolean, Decimal, String
..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

5 Do we know the value of variable Index after it is declared at line 5? Explain your answer [1]

The value of Index after line 5 is UNKNOWN


..............................................................................................................................................................................................................
We do not know the value of Index because the variable was not initialised when it was declared
..............................................................................................................................................................................................................

6 Describe what is happening in this line of code? [2]

Declaring a variable called Total and initialising it to 0. = here is read as BECOMES


..............................................................................................................................................................................................................
Dim is the Visual Basic keyword used when declaring a variable. Integer is a data type.
........................................................................................................................................................................ ......................................
By initialising Total on this line, we are also making the program shorter. One less line of code is needed.
If we did not do it this way, we would need two lines of code, as follows:
Dim Total As Integer
Total = 0
7 What is the difference between Console.Write() and Console.WriteLine()? [2]
Console.Write does not create a new line and the next thing displayed will appear on the SAME line
..............................................................................................................................................................................................................
Console.WriteLine creates a new line and the next thing displayed will appear on the next line and NOT the same line
..............................................................................................................................................................................................................

8 What text will this line of code display on the screen? i.e., what is the value of Index at the end of the
FOR NEXT loop [2]

Index =4
..............................................................................................................................................................................................................
At the end of the FOR NEXT loop (For Index = 0 To 3) Index will be 4 (4 is not ..........................................................
.................................................................................................................................................... less than 4)

9 Why has line 15 been added to this program? What would happen if it was deleted? [2]

If this line was delete then the program would NOT pause and allow you to read what is displayed. It would just
..............................................................................................................................................................................................................

flash quickly and the program would end, with no time for the user to read what was displayed.
..............................................................................................................................................................................................................

10 List at least 4 Visual Basic reserved words in this program? [2]


Sub, Dim, As, Integer, For, To, Next, End
.............................................................................................................................................................. ................................................

11 What is the purpose of the symbol & in Visual Basic. Carefully write out what would be displayed on the screen
at line 13.? [3]

The & or ampersand is used to join information (data) together to create a string. In this line of code the string
..............................................................................................................................................................................................................

"Total = " is joined with the Integer variable Total to display the following (Total is 6 at line 13): Total = 6
..............................................................................................................................................................................................................

12 How would you write the = symbol on line 9 in English? [1]

This line of code reads "Total BECOMES Total plus Index" or "Total BECOMES itself plus Index"
..............................................................................................................................................................................................................

..............................................................................................................................................................................................................
13 It is not possible to use words like “Integer” or “For” as variable identifiers in Visual Basic, why is this? [2]
Integer..............................................................................................................................................................................................................
and For are examples of Visual Basic reserved words. Reserved words are part of the Visual Basic language and

trying to use them as a variable name would result in an error message and prevent your program from starting.
.................................................................................................................................................................... ..........................................

14 When we set the value of a variable at the same time as we declare it is called initialising the variable? Give an
example of where this is happening in this program. Write the line number and the full line of code [2]
6 Dim Total As Integer = 0
..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

15 Write a line of code in Visual Basic code to declare a variable with the identifier “Maximum” that has the data
type “Integer” and that is initialised to -1? [3]
Dim Maximum As Integer = -1
..............................................................................................................................................................................................................

..............................................................................................................................................................................................................

16 Visual Studio 2019 can be used to find a bug in your programming code. What do you need to mark in your
code so that the program will stop during execution (running) and allow you to watch the variables and run the
program one line at a time? [1]
Break point, which will appear as a red circle to the left of the line of code
.................................................................................................................................................................. ............................................

..............................................................................................................................................................................................................

17 Give at least two reasons why you might trace a piece of code that you have not seen before? [4]

Tracing a piece of code helps to you understand what the program does
..............................................................................................................................................................................................................
Tracing a piece of code helps you find any errors in the program
..............................................................................................................................................................................................................

You might also like