Professional Documents
Culture Documents
For Next Trace Table 2
For Next Trace Table 2
For Next Trace Table 2
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,
..............................................................................................................................................................................................................
..............................................................................................................................................................................................................
ForNextTraceTable2
..............................................................................................................................................................................................................
5 Do we know the value of variable Index after it is declared at line 5? Explain your answer [1]
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.
..............................................................................................................................................................................................................
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
..............................................................................................................................................................................................................
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
..............................................................................................................................................................................................................