This page (revision-3) was last changed on 03-Feb-2023 15:21 by Carsten Strotmann 

This page was created on 10-Mar-2010 18:39 by Carsten Strotmann

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
3 03-Feb-2023 15:21 2 KB Carsten Strotmann to previous
2 14-Mar-2010 12:23 2 KB Carsten Strotmann to previous | to last
1 10-Mar-2010 18:39 1 KB Carsten Strotmann to last

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 changed one line
!!! Loops in Forth (pending translation)
!!! Loops in Forth
At line 3 added 52 lines
%%tabbedSection
%%tab-english
I found this small Basic Program in the book "Spielend Programmierer Lernen" from Karl-Heinz Koch:
{{{
10 PRINT CHR$(125)
15 POKE 82,0
20 FOR ZE=0 TO 20
30 FOR SP=0 TO 39
40 POSITION SP,ZE
50 X=INT(RND(0)*26)+65
60 ? CHR$(X)
70 NEXT SP
80 NEXT ZE
}}}
The Program fills the screen with random characters. It uses two nested loops for this.
{{{: RND ( -- n ) \\ Random Number 0-$FF
$D20A C@ ;
\\ Random Numner 0..n-1
: RANDOM ( n -- 0..n-1 )
RND $100 * RND + UM* NIP ;
: POS ( x y -- ) \\ Position Cursor
$54 C! $55 ! ;
: CLS ( -- ) \\ Clear Screen
&125 EMIT ;
: LMARGN ( n -- ) \\ Set left margin
&82 C! ;
: LOOP-DEMO
CLS
0 LMARGN
21 0 DO
40 0 DO
I J POS
26 RANDOM 65 + EMIT
LOOP
LOOP ;
}}}
LOOP-DEMO is the main program. Words to place the coursor and to read a random number, which both are build in the Atari Basic, need to be added to the VolksFORTH Kernel (this means if a programs does not need these functions, they can be left out to save memory)
The Forth words I and J read the loop indicies. I is the index of the inner loop, J is the index of the outer loop. The Forth Program is done without any variables, all values are passed on the Stack
/%
%%tab-german
At line 104 added 3 lines
/%
/%