Loops/Foreach: Difference between revisions

Content added Content deleted
Line 683: Line 683:


DEF AList:POINTER
DEF AList:POINTER

DEF X:INT


AList=ListCreate()
AList=ListCreate()


'add items to the list
'add items to the list
DEF X:INT
FOR X=0 TO 10
FOR X=0 TO 10
POINTER Temp=ListAdd(AList,NEW(INT,1))
POINTER Temp=ListAdd(AList,NEW(INT,1))
#<INT>Temp=X
#<INT>temp=X
'The hash dereference '#' operator is unique to the IWBASIC and Creative Basic languages and is suitable for most basic
'The hash ("#") dereferencing operator is unique to IWBASIC and Creative Basic, and
'pointer needs. IWBASIC also supports a "C style" dereference operator: "*". And "*" will work here too.
'it is suitable for most basic pointer needs. IWBASIC also supports a "C style"
'dereferencing operator: "*". And that will work here too.
NEXT X
NEXT X


'A program compiled as console only does not need 'the commands to open and
'***iterate the list with the "for each" loop***
'close the console. However, it does not hurt to use them.
OPENCONSOLE

'***Iterate the list with the "for each" loop***
FOR Temp=EACH AList AS INT
FOR Temp=EACH AList AS INT


PRINT #Temp
PRINT #Temp
NEXT
NEXT

PRINT

'A press any key to continue message is automatic in a program compiled as a console only
program. I presume the compiler inserts the code.
CLOSECONSOLE

'Because this is a console only program.
END


== An Array ==
== An Array ==
Line 707: Line 722:


AnArray=0,1,2,3,4,5,6,7,8,9,10
AnArray=0,1,2,3,4,5,6,7,8,9,10

OPENCONSOLE


FOR X=0 TO 10
FOR X=0 TO 10
Line 713: Line 730:


NEXT X
NEXT X

PRINT

'a press any key message is automatic when compiled as console only.
CLOSECONSOLE

'Because this is a console only program.
END
</lang>
</lang>