15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

284<br />

Adding Comments to Source Code<br />

By placing such a descriptive comment at the beginning of every subprogram,<br />

other people can understand what the subprogram does and who to<br />

contact (blame) without having to examine the source code line by line.<br />

Debugging<br />

Comments can temporarily ignore lines of code <strong>for</strong> testing. For example, suppose<br />

your program included the following:<br />

Y = log(Y) – (500 + sin(Angle))<br />

X = Rate * exp(X) / Y<br />

PRINT “The value of x = “, X<br />

If you wanted to see how your program would work if you eliminated the<br />

first line of code and replaced it with a new line of code, you could erase the<br />

top line and type a new line, such as<br />

Y = cos(Angle) * Y<br />

X = Rate * exp(X) / Y<br />

PRINT “The value of x = “, X<br />

Now if you wanted to replace the top line with the previously erased line,<br />

you’d have to delete the top line and retype the preceding line all over again.<br />

A simpler method would be to comment out the top line and type in a new<br />

line, such as<br />

‘ Y = log(Y) – (500 + sin(Angle))<br />

Y = cos(Angle) * Y<br />

X = Rate * exp(X) / Y<br />

PRINT “The value of x = “, X<br />

This causes the compiler to ignore the top line (treating it as a comment).<br />

Now if you want to “insert” the top line back into the program, you can comment<br />

out the second line and remove the comment symbol from the first<br />

line:<br />

Y = log(Y) – (500 + sin(Angle))<br />

‘ Y = cos(Angle) * Y<br />

X = Rate * exp(X) / Y<br />

PRINT “The value of x = “, X<br />

The preceding code is equivalent to the following:<br />

Y = log(Y) – (500 + sin(Angle))<br />

X = Rate * exp(X) / Y<br />

PRINT “The value of x = “, X

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!