September Morn Update

This commit is contained in:
Ingy döt Net 2019-09-12 10:33:56 -07:00
parent 4e2d22a71d
commit aac6731f2c
6856 changed files with 141342 additions and 21127 deletions

View file

@ -17,4 +17,6 @@ Use your language's "for each" loop if it has one, otherwise iterate through the
*   [[Loops/N plus one half]]
*   [[Loops/Nested]]
*   [[Loops/While]]
*   [[Loops/with multiple ranges]]
*   [[Loops/Wrong ranges]]
<br><br>

View file

@ -1,6 +1,12 @@
t$={Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday"
in$ ="Not,Hardly,Just,Adequately,Quite,Really,Very,Fantastically,xyzzy"
element$ =""
i =1 ' used to point to successive elements
while word$(t$,i+1,",") <> ""
i = i + 1
print word$(t$,i,",")
wend
do
element$ =word$( in$, i, ",")
if element$ ="xyzzy" then exit do
print element$; " good!"
i =i +1
loop until 1 =2
end

View file

@ -1,5 +1,7 @@
Local i,strs
Define strs = {"Lorem","ipsum","dolor"}
For i, 1, dim(strs)
Disp strs[i]
EndFor
10 DIM A$(9) : REM DECLARE STRING ARRAY
20 REM ADD DATA TO ARRAY AND PRINT ARRAY CONTENTS
30 FOR I=0 TO 8
40 READ A$(I)
50 PRINT A$(I)" ";
60 NEXT
70 DATA THE, QUICK, BROWN, FOX, JUMPS, OVER, THE, LAZY, DOG.

View file

@ -1,8 +1,3 @@
Dim list As New List(Of String)
list.Add("Car")
list.Add("Boat")
list.Add("Train")
For Each item In list
Console.WriteLine(item)
ForEach element()
PrintN(element())
Next

View 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

View file

@ -0,0 +1,5 @@
Local i,strs
Define strs = {"Lorem","ipsum","dolor"}
For i, 1, dim(strs)
Disp strs[i]
EndFor

View file

@ -0,0 +1,13 @@
Public Sub LoopsForeach()
Dim FruitArray() As Variant
Dim Fruit As Variant
FruitArray = [{"Apple","Banana","Strawberry"}]
Dim FruitBasket As Collection
Set FruitBasket = New Collection
For Each Fruit In FruitArray
FruitBasket.Add Fruit
Next Fruit
For Each Fruit In FruitBasket
Debug.Print Fruit
Next Fruit
End Sub

View file

@ -0,0 +1,5 @@
items = Array("Apple", "Orange", "Banana")
For Each x In items
WScript.Echo x
Next

View 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

View file

@ -1,32 +1,9 @@
DEF AList:POINTER
Public Sub Main()
Dim siInput As Short[] = [1, 8, 0, 6, 4, 7, 3, 2, 5, 9]
Dim siTemp As Short
AList=ListCreate()
For Each siTemp In siInput.Sort()
Print siTemp;;
Next
'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
End

View file

@ -1,17 +1,10 @@
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
100 STRING COLLECTION$(1 TO 9)*8
110 LET I=1
120 DO
130 READ IF MISSING EXIT DO:COLLECTION$(I)
140 LET I=I+1
150 LOOP
160 FOR J=1 TO I-1
170 PRINT COLLECTION$(J);" ";
180 NEXT
190 DATA The,quick,brown,fox,jumps,over,the,lazy,dog.

View file

@ -1,12 +1,32 @@
in$ ="Not,Hardly,Just,Adequately,Quite,Really,Very,Fantastically,xyzzy"
element$ =""
i =1 ' used to point to successive elements
DEF AList:POINTER
do
element$ =word$( in$, i, ",")
if element$ ="xyzzy" then exit do
print element$; " good!"
i =i +1
loop until 1 =2
AList=ListCreate()
end
'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

View file

@ -1,3 +1,17 @@
ForEach element()
PrintN(element())
Next
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

View file

@ -1,12 +1,12 @@
import system'routines.
import extensions.
import system'routines;
import extensions;
program =
[
var things := ("Apple", "Banana", "Coconut").
public program()
{
var things := new string[]{"Apple", "Banana", "Coconut"};
things forEach(:thing)
[
console printLine:thing.
]
].
things.forEach:(thing)
{
console.printLine:thing
}
}

View file

@ -0,0 +1,3 @@
Iterable collect;
...
collect.forEach(o -> System.out.println(o));

View file

@ -1,15 +1,23 @@
( Strings: this will display the ASCII code for each character in a string )
"This is a message" [ @ putn space ] ^types'STRING each@
# Strings
( Array: display each element )
needs array'
[ 1 2 3 ] ^array'fromQuote [ @ putn space ] ^types'ARRAY each@
This will display the ASCII code for each character in a string
( Linked List: using the dictionary as an example, display each name )
last [ d->name puts space ] ^types'LIST each@
~~~
'This_is_a_message [ n:put sp ] s:for-each
~~~
( Generic Buffers; display each value in a buffer )
create foo
1 , 3 , 5 ,
# Array
foo 3 [ @ putn space ] ^types'BUFFER each@
Display each element
~~~
{ #1 #2 #3 } [ n:put sp ] a:for-each
~~~
# Linked List
Using the dictionary as an example, display each name
~~~
&Dictionary [ d:name s:put sp ] d:for-each
~~~

View file

@ -0,0 +1,2 @@
let collection = vec![1, 2, 3, 4, 5];
collection.iter().for_each(|elem| println!("{}", elem));

View file

@ -1,3 +1,2 @@
val collection = Array(1, 2, 3, 4)
for (element <- collection)
println(element)
collection.foreach(println)

View file

@ -1,2 +1 @@
for (element <- 1 to 4)
println(element)
(element <- 1 to 4).foreach(println)