Java Reference
In-Depth Information
function writeTimesTable(timesTable)
{
var counter;
var writeString;
for (counter = 1; counter < 12; counter++)
{
writeString = counter + “ * “ + timesTable + “ = “;
writeString = writeString + (timesTable * counter);
writeString = writeString + “<br />”;
document.write(writeString);
}
}
</script>
</head>
<body>
<script type=”text/javascript”>
var timesTable;
for (timesTable = 1; timesTable <= 12; timesTable++)
{
document.write(“<p>”)
writeTimesTable(timesTable)
document.write(“</p>”)
}
</script>
</body>
</html>
Save this as debug_timestable2.htm . Note that there are no errors in this HTML fi le.
The following instructions will walk you through the process of stepping through code.
1.
Set a breakpoint in line 26, the for loop in the body of the page, and reload the page.
2.
Click the Step Into icon and code execution will move to the next statement. Now the fi rst
statement inside the for loop, document.write(“<p>”), is up for execution.
3.
When you click the Step Into icon again, it will take you to the fi rst calling of the
writeTimesTable() function.
4.
You want to see what's happening inside that function, so click Step Into again and you'll step
into the function. Your screen should look like the one shown in Figure 4-9.
5.
Click the Step Into icon a few times to get the gist of the fl ow of execution of the function. In
fact, stepping through code line by line can get a little tedious. So let's imagine you're happy
with this function and want to run the rest of it.
6.
Use Step Out to run the rest of the code. The function has been fully executed, and you're back
the calling line, as you can see from Figure 4-10.
7.
Click the Step Into icon twice to execute document.write() (it won't be visible because it's a
closing tag).
8.
Click Step Into four more times. Execution will continue through the condition and increment-
ing parts of the for loop, ending back at the line that calls the writeTimesTable() function.
Search WWH ::




Custom Search