Friday, October 12, 2012

Use of PRINT and the semicolon

Sometimes when you are sending output to the monitor, you want the cursor to stay on the same line. To make that happen, you still use the PRINT command but you make sure to end the line with a semicolon.

Take a look at this output:

Each of the winning numbers was randomly generated inside a FOR loop except that the output line was terminated by a semicolon, to keep the insertion point on the current line.

Before we can look at the code, review generating random numbers in QBASIC.

Now that you've revisited the random numbers, take a look at this lottery code:

See that cute little semicolon winking at you at the end of the PRINT statement in the FOR loop? That's what is keeping the cursor in place and allowing us to print everything inside the FOR loop on a single line.