Blitz:First Program

From Amiga Coding
Jump to: navigation, search

A simple Blitz basic program is shown below.

NPrint "Hello World!"

MouseWait

End

This program will print the message "Hello World!" without quotes to the default output destination. In most cases this will be the Shell window. The NPrint statement automatically adds a newline character to the end of the message which moves the cursor onto the next line.

The MouseWait command waits for the user to click the mouse button before continuing.

The End statement tells the compiler to exit the program here and tidy up any resources that were used.


Note: The MouseWait command should only be used in certain circumstances, e.g. debugging. This is because it accesses the hardware directly, and so will not work on next generation operating systems like AmigaOS4 and MorphOS. Also, it uses a "busy loop" which uses a lot of CPU time while it waits for the user to click.

A better option might be to replace the MouseWait command with these lines:

NPrint "Press Enter to continue"

dummy$ = Edit$(1)

This version will print the message shown and then wait for the user to press Enter (or Return). The program will sleep while it waits so no CPU time is taken unnecessarily, and it will work with all variations of AmigaOS and derivatives. Edit$(1) waits for up to 1 character to be entered from the Shell.