Your First Program: The first program

We will demonstrate how to write programs in PureBasic by giving you an example. Make sure the PureBasic editor is running, as described in the previous chapter, and type in the following code (or open it from here):

The example code

OpenConsole()
PrintN("Hello, world")
Input()
CloseConsole()
End
If you have typed, or copy and pasted, the code from this manual you will need to save it before you can compile it. Use the "File menu->Save As" item to save the source code to any location and filename you want. You may want to save the file with a ".pb" extension as this is associated with the editor.

Once you have saved the file, you can execute it. Use the "Compiler menu->Compile/Run" item or press the "F5" key. If you have any errors in your source code, compare what you have typed with what is on this page and correct the errors. Make sure to save your code again before compiling and running your program again.

The example running

When you run the program you should see a console window (a text only display window, typically white text on a black background) appear. It will contain the text "Hello, world", and may look something like the image below. Make sure the console window is the active one and press the return key. The console window should now close, which signifies the end of this example.

Output from the first example program