BBC BASIC for Windows
« BEGINNER »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:54pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: BEGINNER  (Read 1053 times)
Ken Down
Guest
xx Re: BEGINNER
« Reply #6 on: Mar 31st, 2010, 04:04am »

For the sake of readability, use upper case for BASIC keywords and lower case for variables.
Did you realise that you can have more than one DIM statement on a line? eg:
DIMx%(5),a$(3),z%50
Integer variables run just slightly faster than real variables, so numeric variables of the form x% or
draw%(20) are better where speed may be important.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: BEGINNER
« Reply #7 on: Mar 31st, 2010, 04:10am »

on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:
Integer variables run just slightly faster than real variables, so numeric variables of the form x% ... are better where speed may be important.


And the (capital letter) static integer variables (A%, B%, C%, ..., Z%) may be even better in that case.


David.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BEGINNER
« Reply #8 on: Mar 31st, 2010, 08:38am »

on Mar 30th, 2010, 11:44pm, Guest-L GRIFFIN wrote:
I could not see how your prog. checked for duplicates

It works exactly like a lottery machine: it picks the first number from the full set of 49, then it picks the second number from the remaining 48, then it picks the third number from the remaining 47, etc. Hence it doesn't generate duplicates.

Quote:
Put the code in a loop and it churned out duplicates at random.

You're right - there was a bug in the code! The line:

Code:
      lotto(R) = max 

should be:

Code:
      lotto(R) = lotto(max) 

Sorry about that.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BEGINNER
« Reply #9 on: Mar 31st, 2010, 09:01am »

on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:
Integer variables run just slightly faster than real variables, so numeric variables of the form x% or draw%(20) are better where speed may be important.

Integer variables may run faster than real variables, but that is not a relevant comparison in this case because the OP is not using real variables but variant variables (he is storing integer values in the variables). Integer variables do not run significantly faster than variant variables (and they make the program longer):

Code:
      i = 123456
      i% = 123456
      
      TIME = 0
      FOR I% = 1 TO 1000000
        j = i + i + i + i + i + i + i + i + i + i : NEXT
      PRINT TIME
      
      TIME = 0
      FOR I% = 1 TO 1000000
        j% = i% + i% + i% + i% + i% + i% + i% + i% + i% + i% : NEXT
      PRINT TIME 

It's true that the static integer variables do run faster, but that's a separate issue.

Note that Acorn versions of BBC BASIC don't have variant variables, so with those there may well be a speed advantage in using integer variables rather than real variables. However this group is specific to BBC BASIC for Windows which, like BBC BASIC (Z80) and BBC BASIC (86) has variant variables.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: BEGINNER
« Reply #10 on: Mar 31st, 2010, 09:10am »

on Mar 31st, 2010, 04:04am, Guest-Ken Down wrote:
For the sake of readability, use upper case for BASIC keywords and lower case for variables.

The preferred naming convention is lower case for local (and private) variables, capitals for constants and a mixture of lower and upper case for global variables.

Because BBC BASIC for Windows supports asynchronous interrupts (e.g. ON SYS and ON TIME) it is important that global and local variables never share the same name. Because you don't (in principle) know what variable names are used in libraries and other CALLed or INSTALLed modules, adhering to a strict naming convention is the only guarantee of that.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls