How do i create a loop using MSX BASIC? (MSX development MSX Forum)MSX Resource Center               
              
English Nederlands Espa�ol Portugu�s Russian French         

MSX Forum


MSX Forum

MSX development - How do i create a loop using MSX BASIC?

Goto page ( Previous Page 1 | 2 | 3 Next Page )
Author

How do i create a loop using MSX BASIC?

GuyveR800
msx guru
Posts: 3048
Posted: September 21 2003, 01:05   
Hmz, it appears you're right
Anyway... I'm a big proponent of extending the MSX BASIC a bit, more in the direction of QBASIC (although SUB's suck). Time is not on my side however
djh1697
msx professional
Posts: 672
Posted: September 21 2003, 11:50   
Quote:

Yeah there is, but you still need the command "GOTO"

10 i=0 ' initialize
20 'Do
30 'do the loop instructions
40 if i<5 then goto 20 'Loop while i<5



of course you could always count backwards

10 loop=5 (or what ever value you want)
20 'loop instruction(s)
20 loop=loop-1
30 if loop<>0 then goto 20

I used to do a lot of machine code programming - on MSX and other 8 bit machines, to count backwards was a lot easier

When you had completed the loop intructions it was a simple case of doing a DEC instruction followed by an XOR intruction. If the result was a none zero you needed to rerun the loop.
GuyveR800
msx guru
Posts: 3048
Posted: September 21 2003, 13:56   
Quote:

10 loop=5 (or what ever value you want)
20 'loop instruction(s)
20 loop=loop-1
30 if loop<>0 then goto 20

I used to do a lot of machine code programming - on MSX and other 8 bit machines, to count backwards was a lot easier



10 for loop=5 to 1 step -1
20 ' loop instructions
30 next

faster and easier...
wolf_

msx legend
Posts: 5178
Posted: September 21 2003, 14:03   
depends on what you wish to do with the loop

if you want to draw pixels from (0,0) to (255,0)

then counting from 0 .. endvalue..

for x=0 to 255
pset(x,0),15
next

is more logical..

..I wouldn't want to count backwards here..
Necron
msx lover
Posts: 113
Posted: September 22 2003, 17:42   
Why do you say that the SUB from QBasico sucks? It is an usefull tool...
msd
msx professional
Posts: 695
Posted: September 22 2003, 18:27   
Counting backwords is amlost for every cpu easier,since the zero flag is set after a dec and no extra compare is needed. Most compilers suck when makeing loops, always a lot of extra jumps etc.
GuyveR800
msx guru
Posts: 3048
Posted: September 22 2003, 20:22   
Also, there's DJNZ.
Funny enough, the x86 equivalent LOOP is discouraged for AMD processors (and Intel too I believe) in favour of a seperate decrease+jump. x86 is such a hack nowadays ^^;
GuyveR800
msx guru
Posts: 3048
Posted: September 22 2003, 20:23   
Quote:

Why do you say that the SUB from QBasico sucks? It is an usefull tool...


Mwah... It's a bit half-assed.. with stupid local variables and ... it just complicates matters too much for a beginners language that BASIC is supposed to be.
Necron
msx lover
Posts: 113
Posted: September 24 2003, 22:06   
Quote:


Mwah... It's a bit half-assed.. with stupid local variables and ... it just complicates matters too much for a beginners language that BASIC is supposed to be.



Come onnnn... Life is beautiful... Don't be so hard to the SUB... haha
Yukio
msx master
Posts: 1048
Posted: September 17 2005, 05:17   
1 for x%=1 to 2
2 if (YourCondition) = (YourCriteria) then x%=2 else x%=1
3 next


Yukio
msx master
Posts: 1048
Posted: September 17 2005, 05:19   
for x%=1 to 2: if (condition)=(criteria) then x%=2 else x%=1
next

ibanezman1990
msx user
Posts: 40
Posted: March 15 2006, 08:37   
Or like this:

10 Cls
20 Print "MSX RESOURCE CENTRE"
30 Beep
40 Goto 20
BiFi
msx guru
Posts: 3142
Posted: March 15 2006, 09:20   
1 CLS:PRINT"MRC":BEEP:POKE-609,118

MäSäXi
msx professional
Posts: 847
Posted: March 29 2006, 11:14   
Quote:

WHILE...WEND and DO...LOOP



I remember BBC had something like that in it´s BASIC. And MSX is atleast 23 years old.


AuroraMSX

msx master
Posts: 1382
Posted: March 29 2006, 17:44   
Quote:

for x%=1 to 2: if (condition)=(criteria) then x%=2 else x%=1
next



DEFINT X
FOR X=1 TO 2
  X = 1 - (condition)=(criteria)
NEXT


'condition = criteria' evaluates to either 0 (false) or -1 (true).
So, X will become 1 when the equation is false/0 and 2 when the equation is true/-1 ...


 
Goto page ( Previous Page 1 | 2 | 3 Next Page )
 







(c) 1994 - 2010 MSX Resource Center Foundation. MSX is a trademark of MSX Licensing Corporation.