2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -1,12 +1,21 @@
{{omit from|GUISS}}
“For” loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
For this task, show how two loops may be nested within each other, with the number of iterations performed by the inner for loop being controlled by the outer for loop. Specifically print out the following pattern by using one for loop nested in another:
“'''For'''”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code.
Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers.
;Task:
Show how two loops may be nested within each other, with the number of iterations performed by the inner for loop being controlled by the outer for loop.
Specifically print out the following pattern by using one for loop nested in another:
<pre>*
**
***
****
*****</pre>
;Reference:
* [[wp:For loop|For loop]] Wikipedia.
<br><br>

View file

@ -0,0 +1,22 @@
* Loops/For - BXH Algol 27/07/2015
LOOPFOR CSECT
USING LOOPFORC,R12
LR R12,R15 set base register
BEGIN LA R2,0 from 1 (from-step=0)
LA R4,1 step 1
LA R5,5 to 5
LOOPI BXH R2,R4,ELOOPI for i=1 to 5 (R2=i)
LA R8,BUFFER-1 ipx=-1
LA R3,0 from 1 (from-step=0)
LA R6,1 step 1
LR R7,R2 to i
LOOPJ BXH R3,R6,ELOOPJ for j:=1 to i (R3=j)
LA R8,1(R8) ipx=ipx+1
MVI 0(R8),C'*' buffer(ipx)='*'
B LOOPJ next j
ELOOPJ XPRNT BUFFER,L'BUFFER print buffer
B LOOPI next i
ELOOPI BR R14 return to caller
BUFFER DC CL80' ' buffer
YREGS
END LOOPFOR

View file

@ -0,0 +1,20 @@
* Loops/For - struct 29/06/2016
LOOPFOR CSECT
USING LOOPFORC,R12
LR R12,R15 set base register
LA R2,1 from 1
DO WHILE=(CH,R2,LE,=H'5') for i=1 to 5 (R2=i)
LA R8,BUFFER-1 ipx=-1
LA R3,1 from 1
DO WHILE=(CR,R3,LE,R2) for j:=1 to i (R3=j)
LA R8,1(R8) ipx=ipx+1
MVI 0(R8),C'*' buffer(ipx)='*'
LA R3,1(R3) j=j+1 (step)
ENDDO , next j
XPRNT BUFFER,L'BUFFER print buffer
LA R2,1(R2) i=i+1 (step)
ENDDO , next i
BR R14 return to caller
BUFFER DC CL80' ' buffer
YREGS
END LOOPFOR

View file

@ -1,23 +0,0 @@
LOOPFORC CSECT
USING LOOPFORC,R12
LR R12,R15 set base register
BEGIN SR R2,R2 from 1
LA R4,1 by 1
LA R5,5 to 5
LOOPI BXH R2,R4,ELOOPI i (R2)
LA R8,BUFFER-1
SR R3,R3 from 1
LA R6,1 by 1
LR R7,R2 to i
LOOPJ BXH R3,R6,ELOOPJ j (R3)
LA R8,1(R8)
MVI 0(R8),C'*'
B LOOPJ
ELOOPJ XPRNT BUFFER,L'BUFFER
B LOOPI
ELOOPI EQU *
RETURN XR R15,R15 set return code
BR R14 return to caller
BUFFER DC CL80' '
YREGS
END LOOPFORC

View file

@ -1,6 +1,11 @@
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT "*";
NEXT j
PRINT
NEXT i
If OpenConsole()
Define i, j
For i=1 To 5
For j=1 To i
Print("*")
Next j
PrintN("")
Next i
Print(#LFCR$+"Press ENTER to quit"): Input()
CloseConsole()
EndIf

View file

@ -1,7 +1,6 @@
Public OutConsole As Scripting.TextStream
For i = 0 To 4
For j = 0 To i
OutConsole.Write "*"
Next j
OutConsole.WriteLine
Next i
FOR i = 1 TO 5
FOR j = 1 TO i
PRINT "*";
NEXT j
PRINT
NEXT i

View file

@ -1,6 +1,7 @@
For x As Integer = 0 To 4
For y As Integer = 0 To x
Console.Write("*")
Next
Console.WriteLine()
Next
Public OutConsole As Scripting.TextStream
For i = 0 To 4
For j = 0 To i
OutConsole.Write "*"
Next j
OutConsole.WriteLine
Next i

View file

@ -1,6 +1,6 @@
10 FOR i = 1 TO 5
20 FOR j = 1 TO i
30 PRINT "*";
40 NEXT j
50 PRINT
60 NEXT i
For x As Integer = 0 To 4
For y As Integer = 0 To x
Console.Write("*")
Next
Console.WriteLine()
Next

View file

@ -1,19 +1,7 @@
OPENCONSOLE
FOR X=1 TO 5
FOR Y=1 TO X
LOCATE X,Y:PRINT"*"
NEXT Y
NEXT X
PRINT
CLOSECONSOLE
FOR n = 1 to 5 CYCLE
FOR k = 1 to n CYCLE
print "*";
REPEAT
PRINT
REPEAT
END
'Could also have been written the same way as the Creative Basic example, with no LOCATE command.

View file

@ -1,6 +1,19 @@
for i = 1 to 5
for j = 1 to i
print "*";
next
print
next
OPENCONSOLE
FOR X=1 TO 5
FOR Y=1 TO X
LOCATE X,Y:PRINT"*"
NEXT Y
NEXT X
PRINT
CLOSECONSOLE
END
'Could also have been written the same way as the Creative Basic example, with no LOCATE command.

View file

@ -1,11 +1,6 @@
If OpenConsole()
Define i, j
For i=1 To 5
For j=1 To i
Print("*")
Next j
PrintN("")
Next i
Print(#LFCR$+"Press ENTER to quit"): Input()
CloseConsole()
EndIf
for i = 1 to 5
for j = 1 to i
print "*";
next
print
next

View file

@ -0,0 +1,13 @@
#import system.
#import extensions.
#symbol program =
[
0 till:5 &doEach:i
[
0 to:i &doEach:j
[ console write:"*". ].
console writeLine.
].
].

View file

@ -0,0 +1 @@
for i <- 1..5, do: IO.puts (for j <- 1..i, do: "*")

View file

@ -0,0 +1,6 @@
fun main(args: Array<String>) {
(1..5).forEach {
(1..it).forEach { print('*') }
println()
}
}

View file

@ -0,0 +1 @@
1 1 5 {dup {`*'} repeat bdup bpop ncat `\n' cat print} for flush

View file

@ -1,7 +1,10 @@
do i=1 to 5
s=''
do j=1 to i
s=s || '*'
end
say s
end
/*REXX program demonstrates an outer DO loop controlling the inner DO loop with a "FOR".*/
do j=1 for 5 /*this is the same as: do j=1 to 5 */
$= /*initialize the value to a null string*/
do k=1 for j /*only loop for a J number of times*/
$=$ || '*' /*using concatenation (||) for build.*/
end /*k*/
say $ /*display character string being built.*/
end /*j*/
/*stick a fork in it, we're all done. */

View file

@ -1,7 +1,10 @@
do i=1 for 5
s=''
do i
s=s'*'
end
say s
end
/*REXX program demonstrates an outer DO loop controlling the inner DO loop with a "FOR".*/
do j=1 for 5 /*this is the same as: do j=1 to 5 */
$= /*initialize the value to a null string*/
do k=1 for j /*only loop for a J number of times*/
$=$'*' /*using abutment for the construction. */
end /*k*/
say $ /*display character string being built.*/
end /*j*/
/*stick a fork in it, we're all done. */

View file

@ -8,3 +8,14 @@ do n=1 to 5;
put a;
end;
run;
/* Possible without the inner loop. Notice TRIM is replaced with STRIP,
otherwise there is a blank space on the left */
data _null_;
length a $5;
do n=1 to 5;
a=strip(a) !! "*";
put a;
end;
run;

View file

@ -0,0 +1,6 @@
for i in {1..5} loop
for j in {1..i} loop
nprint( '*' );
end loop;
print; -- new line
end loop;

View file

@ -0,0 +1,11 @@
Option Explicit
Sub LoopEx()
Dim i As Long, j As Long, s As String
For i = 1 To 5
s = ""
For j = 1 To i
s = s + "*"
Next
Debug.Print s
Next
End Sub

View file

@ -0,0 +1,9 @@
Option Explicit
Dim i, j, s
For i = 1 To 5
s = ""
For j = 1 To i
s = s + "*"
Next
WScript.Echo s
Next

View file

@ -0,0 +1,9 @@
int main (string[] args) {
for (var i = 1; i <= 5; i++) {
for (var j = 1; j <= i; j++) {
stdout.putc ('*');
}
stdout.putc ('\n');
}
return 0;
}