Not all analyses will be as thorough as this one, since future ones will only discuss new issues.
The purpose of this command is to open the console window that appears when you run your program. It has no parameters (there is nothing between the parentheses) and returns a value showing whether the console window was opened successfully or not. However, in this case we are ignoring the returned value for simplicity, and because we have not yet covered the keywords required to handle it.
The second instruction in the program was PrintN("Hello, world"). This is another command (as you can see by the parenthesis).
The PrintN command writes text to a console window and then moves onto the next line, therefore we use this to print the "Hello, world" text in the console. The PrintN command has one parameter which must be a string. In this case, we use the fixed string "Hello, world" (remember, from the fundamentals, fixed strings are sequences of characters enclosed within inverted commas). The PrintN command does not return a value.
The third instruction was Input(), which is, again, a command. It has no parameters and the result is not being used. This command will take input from the user (as text typed in a console window) until the user presses the return key. The reason for using this command is to pause the program and give the user a chance to see what we printed in the console window. If the Input command was not in the program then there would be no pause; the console window would close and the program would exit before we could see anything. So even using it in this simple way is very useful.
Next, the CloseConsole() command is called. Again, there are no parameters and it has no result. As you may also have guessed, this command closes the console window. It is always a good idea to close or free anything you open, create or allocate in a program, although all of PureBasics libraries will normally automatically do this for you when the program ends.
Finally, there is the End keyword (you know it is a keyword because there are no parentheses). The purpose of the End keyword is to tell your program to stop running and exit.
It is only the end of the program when that instruction is executed, not when it is found by the compiler in your source code. Commonly you may store data or more code after an End instruction if you would not want the computer to try to execute it without specifically telling it to. So you use the End instruction to make sure the program has stopped before that point.
| Previous topic | Chapter contents | Next topic |
|---|---|---|
| Your first program! | User Guide contents | Summary |