Loops/Foreach: Difference between revisions

Line 683:
 
DEF AList:POINTER
 
DEF X:INT
 
AList=ListCreate()
 
'add items to the list
DEF X:INT
FOR X=0 TO 10
POINTER Temp=ListAdd(AList,NEW(INT,1))
#<INT>Temptemp=X
'The hash dereference '("#'") dereferencing operator is unique to the IWBASIC and Creative Basic languages, and is suitable for most basic
'it is suitable for most basic pointer needs. IWBASIC also supports a "C style" dereference operator: "*". And "*" will work here too.
'dereferencing operator: "*". And that will work here too.
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
 
'***iterateIterate the list with the "for each" loop***
FOR Temp=EACH AList AS INT
 
PRINT #Temp
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 ==
Line 707 ⟶ 722:
 
AnArray=0,1,2,3,4,5,6,7,8,9,10
 
OPENCONSOLE
 
FOR X=0 TO 10
Line 713 ⟶ 730:
 
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>