do...while condition in BASIC V2

SYS 64738
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

do...while condition in BASIC V2

Post by Shaun_B »

Here's a quick snippet that you may find useful, it's the equivalent of a do...while loop in C and C-derived languages:

Code: Select all

10 poke 53280,0:poke 53281,0:poke 646,1:print"{clear}";
20 print "   ..press the any key to continue.."
30 for i=-1 to 0: get a$
40 rem put your logic here
50 i=(a$=""):next
If this was C, the corresponding (untested) listing might be:

Code: Select all

#include<stdio.h>
int main()
{
    char a = '';
    printf("   ..Press the any key to continue..");
    do
    {
        a = _getch();
        // Logic goes here
    } while (c == '')
}
Regards,

Shaun.


BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
satpro

Re: do...while condition in BASIC V2

Post by satpro »

I'm out of touch with BASIC programming, but I seem to remember that using integers (in the loop counter, for example) is much faster than floating point. Is that true?
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: do...while condition in BASIC V2

Post by Shaun_B »

satpro wrote:I'm out of touch with BASIC programming, but I seem to remember that using integers (in the loop counter, for example) is much faster than floating point. Is that true?
I think it depends on what you're doing, for instance, x=rnd(0)*38 is quicker than x=int(rnd(0)*38) I think. For instance:

Code: Select all

0 x=rnd(0)*16
10 print tab(x);"at position:";x
would be quicker. Also, Commodore BASIC, I think there is a bug in the integers in that there is a some bits set that are invisible to the user (like x = 10, so x is actually 10.00000000001 or something like that).

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: Google [Bot] and 6 guests