September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
7
Task/Loops-Foreach/BASIC/loops-foreach-1.basic
Normal file
7
Task/Loops-Foreach/BASIC/loops-foreach-1.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
DIM collection$(1)
|
||||
collection$ = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog." }
|
||||
|
||||
FOR i = 0 TO collection$[?]-1
|
||||
PRINT collection$[i]+ " ";
|
||||
NEXT i
|
||||
PRINT
|
||||
6
Task/Loops-Foreach/BASIC/loops-foreach-10.basic
Normal file
6
Task/Loops-Foreach/BASIC/loops-foreach-10.basic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
t$={Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
|
||||
|
||||
while word$(t$,i+1,",") <> ""
|
||||
i = i + 1
|
||||
print word$(t$,i,",")
|
||||
wend
|
||||
5
Task/Loops-Foreach/BASIC/loops-foreach-11.basic
Normal file
5
Task/Loops-Foreach/BASIC/loops-foreach-11.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Local i,strs
|
||||
Define strs = {"Lorem","ipsum","dolor"}
|
||||
For i, 1, dim(strs)
|
||||
Disp strs[i]
|
||||
EndFor
|
||||
8
Task/Loops-Foreach/BASIC/loops-foreach-12.basic
Normal file
8
Task/Loops-Foreach/BASIC/loops-foreach-12.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Dim list As New List(Of String)
|
||||
list.Add("Car")
|
||||
list.Add("Boat")
|
||||
list.Add("Train")
|
||||
|
||||
For Each item In list
|
||||
Console.WriteLine(item)
|
||||
Next
|
||||
8
Task/Loops-Foreach/BASIC/loops-foreach-2.basic
Normal file
8
Task/Loops-Foreach/BASIC/loops-foreach-2.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
DIM collection$(8)
|
||||
collection$() = "The", "quick", "brown", "fox", "jumps", \
|
||||
\ "over", "the", "lazy", "dog."
|
||||
|
||||
FOR index% = 0 TO DIM(collection$(), 1)
|
||||
PRINT collection$(index%) " ";
|
||||
NEXT
|
||||
PRINT
|
||||
11
Task/Loops-Foreach/BASIC/loops-foreach-3.basic
Normal file
11
Task/Loops-Foreach/BASIC/loops-foreach-3.basic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
10 DIM A$(9) :REM DECLARE STRING ARRAY
|
||||
20 REM *** FILL ARRAY WITH WORDS ***
|
||||
30 FOR I = 0 TO 8
|
||||
40 READ A$(I)
|
||||
50 NEXT
|
||||
60 REM *** PRINT ARRAY CONTENTS ***
|
||||
70 FOR I = 0 TO 8
|
||||
80 PRINT A$(I)" ";
|
||||
90 NEXT
|
||||
100 END
|
||||
1000 DATA THE, QUICK, BROWN, FOX, JUMPS, OVER, THE, LAZY, DOG.
|
||||
19
Task/Loops-Foreach/BASIC/loops-foreach-4.basic
Normal file
19
Task/Loops-Foreach/BASIC/loops-foreach-4.basic
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
DEF AnArray[11]:INT
|
||||
|
||||
AnArray=0,1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
'A console only program will work without OPENCONSOLE and
|
||||
'CLOSECONSOLE; however, it does not hurt to use them.
|
||||
OPENCONSOLE
|
||||
|
||||
FOR X=0 TO 10
|
||||
PRINT AnArray[X]
|
||||
NEXT X
|
||||
|
||||
'keep the console from closing right away.
|
||||
DO:UNTIL INKEY$<>""
|
||||
|
||||
CLOSECONSOLE
|
||||
|
||||
'because this is a console only program.
|
||||
END
|
||||
18
Task/Loops-Foreach/BASIC/loops-foreach-5.basic
Normal file
18
Task/Loops-Foreach/BASIC/loops-foreach-5.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
' FB 1.05.0
|
||||
|
||||
' FreeBASIC doesn't have a foreach loop but it's easy to manufacture one using macros
|
||||
|
||||
#Macro ForEach(I, A)
|
||||
For _i as integer = LBound(A) To UBound(A)
|
||||
#Define I (A(_i))
|
||||
#EndMacro
|
||||
|
||||
#Define In ,
|
||||
|
||||
Dim a(-5 To 5) As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||
ForEach(i in a)
|
||||
Print i; " ";
|
||||
Next
|
||||
|
||||
Print
|
||||
Sleep
|
||||
32
Task/Loops-Foreach/BASIC/loops-foreach-6.basic
Normal file
32
Task/Loops-Foreach/BASIC/loops-foreach-6.basic
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
DEF AList:POINTER
|
||||
|
||||
AList=ListCreate()
|
||||
|
||||
'Add items to the list.
|
||||
DEF X:INT
|
||||
|
||||
FOR X=0 TO 10
|
||||
POINTER Temp=ListAdd(AList,NEW(INT,1))
|
||||
#<INT>temp=X
|
||||
'The hash ("#") dereferencing operator is unique to IWBASIC and Creative Basic, and
|
||||
'it is suitable for most basic pointer needs. IWBASIC also supports a "C style"
|
||||
'dereferencing operator: "*". And that will work here too.
|
||||
NEXT X
|
||||
|
||||
'A program compiled as console only does not need the commands to open and
|
||||
'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
|
||||
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
|
||||
17
Task/Loops-Foreach/BASIC/loops-foreach-7.basic
Normal file
17
Task/Loops-Foreach/BASIC/loops-foreach-7.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
DEF AnArray[11]:INT
|
||||
|
||||
AnArray=0,1,2,3,4,5,6,7,8,9,10
|
||||
|
||||
OPENCONSOLE
|
||||
|
||||
FOR X=0 TO 10
|
||||
PRINT AnArray[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
|
||||
12
Task/Loops-Foreach/BASIC/loops-foreach-8.basic
Normal file
12
Task/Loops-Foreach/BASIC/loops-foreach-8.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
in$ ="Not,Hardly,Just,Adequately,Quite,Really,Very,Fantastically,xyzzy"
|
||||
element$ =""
|
||||
i =1 ' used to point to successive elements
|
||||
|
||||
do
|
||||
element$ =word$( in$, i, ",")
|
||||
if element$ ="xyzzy" then exit do
|
||||
print element$; " good!"
|
||||
i =i +1
|
||||
loop until 1 =2
|
||||
|
||||
end
|
||||
3
Task/Loops-Foreach/BASIC/loops-foreach-9.basic
Normal file
3
Task/Loops-Foreach/BASIC/loops-foreach-9.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
ForEach element()
|
||||
PrintN(element())
|
||||
Next
|
||||
Loading…
Add table
Add a link
Reference in a new issue