Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,3 +1,4 @@
|
|||
{{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:
|
||||
|
|
|
|||
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
note: Iteration
|
||||
|
|
|
|||
4
Task/Loops-For/ALGOL-60/loops-for.alg
Normal file
4
Task/Loops-For/ALGOL-60/loops-for.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
FOR i:=1 UNTIL 5 DO
|
||||
FOR j:=1 UNTIL i DO
|
||||
OUTTEXT("*");
|
||||
OUTLINE
|
||||
8
Task/Loops-For/AppleScript/loops-for.applescript
Normal file
8
Task/Loops-For/AppleScript/loops-for.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set x to return
|
||||
repeat with i from 1 to 5
|
||||
repeat with j from 1 to i
|
||||
set x to x & "*"
|
||||
end repeat
|
||||
set x to x & return
|
||||
end repeat
|
||||
return x
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
Local i,j
|
||||
ClrIO
|
||||
For i, 1, 5
|
||||
For j, 1, i
|
||||
Output i*8, j*6, "*"
|
||||
EndFor
|
||||
EndFor
|
||||
Public OutConsole As Scripting.TextStream
|
||||
For i = 0 To 4
|
||||
For j = 0 To i
|
||||
OutConsole.Write "*"
|
||||
Next j
|
||||
OutConsole.WriteLine
|
||||
Next i
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
'This Prints to the Debug-Window!
|
||||
Dim i As Integer
|
||||
Dim ii As Integer
|
||||
Dim x As Integer
|
||||
Dim out As String
|
||||
|
||||
output = ""
|
||||
|
||||
For i = 1 To 5
|
||||
For ii = 1 To i
|
||||
out = out + "*"
|
||||
Next ii
|
||||
Debug.Print (out)
|
||||
out = ""
|
||||
Next i
|
||||
For x As Integer = 0 To 4
|
||||
For y As Integer = 0 To x
|
||||
Console.Write("*")
|
||||
Next
|
||||
Console.WriteLine()
|
||||
Next
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
For x As Integer = 0 To 4
|
||||
For y As Integer = 0 To x
|
||||
Console.Write("*")
|
||||
Next
|
||||
Console.WriteLine()
|
||||
Next
|
||||
10 FOR i = 1 TO 5
|
||||
20 FOR j = 1 TO i
|
||||
30 PRINT "*";
|
||||
40 NEXT j
|
||||
50 PRINT
|
||||
60 NEXT i
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
star_triangle: { <- { { "*" << } iter times "\n" << } -> times }
|
||||
main: { 10 star_triangle }
|
||||
*
|
||||
**
|
||||
***
|
||||
****
|
||||
*****
|
||||
******
|
||||
*******
|
||||
********
|
||||
*********
|
||||
((main { 10 star_triangle ! })
|
||||
|
||||
(star_triangle {
|
||||
dup
|
||||
<-
|
||||
{ dup { "*" << } <->
|
||||
iter - 1 +
|
||||
times
|
||||
"\n" << }
|
||||
->
|
||||
times }))
|
||||
|
|
|
|||
14
Task/Loops-For/Oberon-2/loops-for.oberon-2
Normal file
14
Task/Loops-For/Oberon-2/loops-for.oberon-2
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
MODULE LoopFor;
|
||||
IMPORT
|
||||
Out;
|
||||
VAR
|
||||
i, j: INTEGER;
|
||||
|
||||
BEGIN
|
||||
FOR i := 1 TO 5 DO
|
||||
FOR j := 1 TO i DO
|
||||
Out.Char('*');
|
||||
END;
|
||||
Out.Ln
|
||||
END
|
||||
END LoopFor.
|
||||
6
Task/Loops-For/PL-I/loops-for-1.pli
Normal file
6
Task/Loops-For/PL-I/loops-for-1.pli
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
do i = 1 to 5;
|
||||
do j = 1 to i;
|
||||
put edit ('*') (a);
|
||||
end;
|
||||
put skip;
|
||||
end;
|
||||
1
Task/Loops-For/PL-I/loops-for-3.pli
Normal file
1
Task/Loops-For/PL-I/loops-for-3.pli
Normal file
|
|
@ -0,0 +1 @@
|
|||
put edit ((('*' do j = 1 to i)do i=1 to 5))(a); /* no new line */
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
for i in 1..5
|
||||
for j in 1..i
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
for j in 1..i
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
1.upto(5) do |i|
|
||||
1.upto(i) do |j|
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
(1..5).each do |i|
|
||||
(1..i).each do |j|
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
5.times do |i|
|
||||
# i goes from 0 to 4
|
||||
(i+1).times do
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
1.upto(5) do |i|
|
||||
1.upto(i) do |j|
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
i = 1
|
||||
loop do
|
||||
j = 1
|
||||
loop do
|
||||
print "*"
|
||||
break if (j += 1) > i
|
||||
end
|
||||
puts
|
||||
break if (i += 1) > 5
|
||||
5.times do |i|
|
||||
# i goes from 0 to 4
|
||||
(i+1).times do
|
||||
print "*"
|
||||
end
|
||||
puts
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1 +1,10 @@
|
|||
puts (1..5).map { |i| "*" * i }
|
||||
i = 1
|
||||
loop do
|
||||
j = 1
|
||||
loop do
|
||||
print "*"
|
||||
break if (j += 1) > i
|
||||
end
|
||||
puts
|
||||
break if (i += 1) > 5
|
||||
end
|
||||
|
|
|
|||
1
Task/Loops-For/Ruby/loops-for-6.rb
Normal file
1
Task/Loops-For/Ruby/loops-for-6.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
puts (1..5).map { |i| "*" * i }
|
||||
4
Task/Loops-For/Simula/loops-for.simula
Normal file
4
Task/Loops-For/Simula/loops-for.simula
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
FOR I:=1 UNTIL 5 DO
|
||||
FOR J:=1 UNTIL I DO
|
||||
OUTTEXT("*");
|
||||
OUTLINE
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
PROGRAM:FORLOOPS
|
||||
:ClrHome
|
||||
:For(I,1,5)
|
||||
:For(J,1,I)
|
||||
:Output(I,J,"*")
|
||||
:End
|
||||
:End
|
||||
ClrHome
|
||||
For(I,1,5)
|
||||
For(J,1,I)
|
||||
Output(I,J,"*")
|
||||
End
|
||||
End
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue