In my previous post yesterday, I promise that the concluding part will be published today....So lets continue from where I stopped yesterday.

>Step 7: The GOTO instruction tells the PC to jump to a specified line number. SmallBasic also uses the IF statement, allowing you to have multiple conditions. For example, ‘IF N = 10 AND K = 0 THEN GOTO 50’. We’re also introducing the INPUT statement and END. Strictly speaking, all programs should end with END.

>Step 8: GOTO can generate loops, but FOR and NEXT provide a better solution. The code between the two statements is executed for each value of the variable in the FOR statement (our program displays numbers from 1 to 10 and their squares). You can also specify a step in FOR, such as ‘FOR N = 2 TO 100 STEP 2’.

>Step 9: In step 2 we saw a syntax error. This type of error is picked up before you try to run a program; others are encountered only when a program is run. The above program illustrates this – have a go yourself. It will work fine until 1 equals 0 and the program is unable to divide by zero.

>Step 10: Here’s another error. Run the program and enter ‘1’ when prompted. It will terminate properly. Run it again and enter ‘0.3’. The program won’t end because N never equals 10. Click BRK in the status bar to force it to stop. Noting that RUN has changed to BRK proves a program is running, possibly in an infinite loop.

>Step 11: Programs sometimes require data that can be read from an external file or included in the program as DATA statements and accessed using the READ statement. You can include as many values as you want on a DATA statement. This program would work the same way if all the values were in one long DATA statement.

>Step 12: Using DATA and READ saved us using lots of assignment statements (such as X = 108), but it doesn’t produce a very exciting or useful result. Change the first PRINT statement to ’20 SET X, Y COLOR 5’ and the second to ’50 LINE X, Y COLOR 5’. Check the Output tab matches the screenshot below.

>Step 13: Add ‘1 REM’ as the first line of the program and run it again. It’ll work exactly the same. REM (remark) statements are ignored, but useful for adding comments. Get into the habit of including REM statements – they make your programs far easier to understand if you want to change them later.

>Step 14: If you want to use values in the DATA statement more than once, use the RESTORE statement. This causes the next READ to return to the specified line (for example, RESTORE 100). Now try it: modify the program to draw two or more of these symbols, each offset by 10 pixels using a FOR/NEXT loop.

::: You can Like our facebook page to follow us whenever new post is published...Page name: Naija info and Tech.

Related Posts:

  • How to post a document to FacebookHey friends! Hope you are doing great. Today I want to share with us how you can upload a document on facebook. I have been looking for how this could be done for a very long time until I just find out this simple steps: R… Read More
  • Online Tools To Tells More About WebsitesHave you ever noticed and wondered why some websites or blogs loads faster than yours? Ever wondered who is hosting those high-traffic websites? If you got questions like these, here are some of the most useful free online we… Read More
  • Review! Samsung Galaxy Note 10.1The Samsung Galaxy Note 10.1 2014 Edition doesn't come cheap, (£400) but that money will buy you a great, high-definition display, rafts of power and a handy stylus for writing notes or doodling cartoons. Samsung's… Read More
  • Android Users... Stop Wasting Your Airtime To BrowseHello friend! Today, I want to share or teach us methods we can use to surf the web without wasting money or much megabyte. This is not cheats o. I know the reason many keep running away for android smartphone is becaus… Read More
  • Review: Nokia Lumia 1320Nokia lumia 1320 is the latest window 8 mobile phone, it was launch on January of last month. Let's look at some of the phone features. Network The phone has 2G Network; GSM 850 / 900 / 1800 / 1900 - all versions, 3G Net… Read More

0 comments:

Post a Comment

Popular Posts