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.
8:20:00 am
olusola salau
No comments
Related Posts:
Top 5 Blogging Softwares for Bloggers Today, starting a blog os the easiest task out there. With a very minimal cost, you can start up your own blog within 1-3 hours. And if you’re skillful enough, you can make money out of your blog too. But, if you’… Read More
How/Where to Buy MTN SME Data Bundle at low PriceThe best data bundle plan for Android users, iphone and Pc is the new MTN SME Data bundle. What is MTN SME Data Bundle? MTN SME Data Share is a prepaid service that allows business owners to buy data bundles and share with th… Read More
How to Fix Cannot Play DVD Error on WindowIn our modern computer age with Windows 7 and Windows 8, you can still receive an error like “Windows Media Player cannot play this DVD because there is problem with digital copy protection” when you’re tryi… Read More
MTN SME Data ShareWhat is MTN SME Data Share? MTN SME Data Share is a prepaid service that allows business owners or individual to buy data bundles and share with others. There is no limit to data share as long as the sponsor has enough da… Read More
Ready For Nigeria Market: Samsung Galaxy Note 4Samsung Electronics says that its Galaxy Note 4 will officially go on sale in Nigeria as from Friday, October 24, 2014. The device would be available for purchase through all authorised Samsung partner stores and telecoms ope… Read More
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment