A-A+

How to build your programming code

2019-04-09 Technology No comment

I remember that I used the basic functionality on my ZX Spectrum computer for the first time in the 1980s, looking through the basic commands and sample code pages, not knowing how to write the program myself. It's like reading a dictionary where I can learn certain words and their meaning, and have limited information about how to construct them into whole sentences to write a document. Every programmer involved in a basic program may have encountered the famous "Hello Word" program, which consists of a two-line program that prints the phrase indefinitely on the screen.

Your program code needs to be written as a step-by-step instruction using commands that you understand in the programming language of your choice. This means reading your programming manual to see what commands you need to use to perform the actions you want the program to perform. In the "Hello World" example, you first need a command to print "Hello World" on the screen, and then you need a second command to print it again without having to write multiple print statements.

Take a look at this example. For the sake of simplicity, I am using the old basic line number – probably because I am a retro mania.

10 print "Hello World"

from

20 go to 10

The best structure for writing any program code is to make it clear and easy to understand. Some programmers put multiple commands on one line, which may make your code difficult to understand if you try to eliminate the error. Extending the code to multiple lines actually makes the program work better and becomes more readable.

Another suggested approach is to use the REM statement to separate each part of the program code. REM [short for notes] allows you to add comments before each piece of code to remind you of the features of each part. This is very useful if you want to edit the code later.

10 rem setting variable

from

20 let A = 1: let B = 2

from

30 rem *******

from

40 rem prints variables to the screen

from

50 rem *******

from

60 printing A, B

Anything after the computer ignores the REM command, you can use as many REM statements as possible to create larger gaps in your code for reading. Other programming languages ​​allow you to use the first line of a blank line or indent routine.

Now I will show you how to build the entire program code. Keep in mind that computers need to follow step-by-step instructions, so you need to write each instruction in the order you want it to run.

Code building

Set screen resolution and variables: The first part of the program will set the screen resolution and variables.

Read the information into an array: If you want to use the DIM command to put information into the array, you can use the For / Next loop and the READ command. It is best to read the data statement of the array at the end of the program.

Set the main screen: This is the part of the main screen that you will use to set up the GOSUB Command. In a shooter type game, you will have a routine that draws the sprite and game screen and then returns the next line of code from which it came.

Main program loop: After the program starts and runs, the main program loops through the subroutine to jump to various routines and then returns to the next line in the loop.

Program routine: Placing all programming routines after the main loop is a good structure. You can use a separate routine to update the screen, check the joystick input, check for collision detection, and more. After each check, you will return to the main loop.

Data statement: Finally, you can list all the data statements at the end of the program to make them easier to find and correct when needed.

in conclusion

Creating code with a lot of REM statements and short lines can make your code look clearer and easier to understand. You might want to improve the program or use routines from other programs.

Compuclever Antivirus Plus,Click here! New Neuro-editing Technology For Ultimate Wealth Success (view mobile),Click here!

leave me a message

Copyright@WaiWaitech inc. © Technology All rights reserved.  

User login ⁄ Register

Share: