Friday, November 3, 2017

Chapter 4 - DO...LOOP


Let's start a new program. To get rid of the old program, click on "File" on QBASIC's menu and you will see the File menu with New, Open..., Save, and others. Click on "New". QBASIC will now tell you that your current program is not saved, and it will ask if you want to "Save it now?". Let's not save it. You can always type it in again. Click on < No > with the mouse. We'll learn how to save programs in Chapter 8.
Now you should have a clean blue screen. Type in this program:

     DO
       PRINT "Ted was here ";
     LOOP
Make sure you get the semi-colon (;) at the end of the PRINT line, and the space between the word "here" and the last quotation mark. You don't need to use my name, put yours in there instead ("Jack was here ", or whatever). Now run it.

DO...LOOP

DO and LOOP will do whatever is between the DO and the LOOP over and over again.

Give me a Break!

Ok, that's great. HOW DO I STOP IT!? Press the <Ctrl> (Control) key and hold it down while pressing the <Pause> key. The <Pause> key is usually at the top of the keyboard and all the way over to the right. This is called "pressing the <Break> key." Don't worry, it doesn't really break your program, it just stops it and takes you back to QBASIC. Maybe it should have been called the "brake" key.
On laptop keyboards, the break key might be a little harder to figure out. Sometimes you have to press the "Fn" key followed by the key that says break. Sometimes it is color-coded to help you figure it out. You'll know you have it when the program stops and the editor comes back up.

Neatness Counts

Notice that PRINT has two spaces in front of it. This is called "indenting" and it makes the program easier to read. You can see the beginning and the end of the DO...LOOP more clearly. QBASIC doesn't care about indenting, only people do. It's important to make your programs look nice so other people can read them.

Learned

  • File | New
  • DO...LOOP
  • <Break>

No comments:

Post a Comment