A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
7
Task/Loops-N-plus-one-half/0DESCRIPTION
Normal file
7
Task/Loops-N-plus-one-half/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Quite often one needs loops which, in the last iteration, execute only part of the loop body. The goal of this task is to demonstrate the best way to do this.
|
||||
|
||||
Write a loop which writes the comma-separated list
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
using separate output statements for the number and the comma from within the body of the loop.
|
||||
|
||||
See also: [[Loop/Break]]
|
||||
2
Task/Loops-N-plus-one-half/1META.yaml
Normal file
2
Task/Loops-N-plus-one-half/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: Iteration
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(defun print-list (xs)
|
||||
(progn$ (cw "~x0" (first xs))
|
||||
(if (endp (rest xs))
|
||||
(cw (coerce '(#\Newline) 'string))
|
||||
(progn$ (cw ", ")
|
||||
(print-list (rest xs))))))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
FOR i WHILE
|
||||
print(whole(i, -2));
|
||||
# WHILE # i < 10 DO
|
||||
print(", ")
|
||||
|
||||
OD;
|
||||
|
||||
print(new line)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
FOR i TO 10 DO
|
||||
print(whole(i, -2));
|
||||
IF i < 10 THEN
|
||||
print(", ")
|
||||
FI
|
||||
OD;
|
||||
|
||||
print(new line)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
FOR i DO
|
||||
print(whole(i, -2));
|
||||
IF i >= 10 THEN GO TO done FI;
|
||||
print(", ")
|
||||
|
||||
OD;
|
||||
done:
|
||||
print(new line)
|
||||
2
Task/Loops-N-plus-one-half/AWK/loops-n-plus-one-half.awk
Normal file
2
Task/Loops-N-plus-one-half/AWK/loops-n-plus-one-half.awk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
$ awk 'BEGIN{for(i=1;i<=10;i++){printf i;if(i<10)printf ", "};print}'
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
14
Task/Loops-N-plus-one-half/Ada/loops-n-plus-one-half.ada
Normal file
14
Task/Loops-N-plus-one-half/Ada/loops-n-plus-one-half.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
|
||||
|
||||
procedure Loop_And_Half is
|
||||
I : Positive := 1;
|
||||
begin
|
||||
loop
|
||||
Put(Item => I, Width => 1);
|
||||
exit when I = 10;
|
||||
Put(", ");
|
||||
I := I + 1;
|
||||
end loop;
|
||||
New_Line;
|
||||
end Loop_And_Half;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
PROC main()
|
||||
DEF i
|
||||
FOR i := 1 TO 10
|
||||
WriteF('\d', i)
|
||||
EXIT i = 10
|
||||
WriteF(', ')
|
||||
ENDFOR
|
||||
ENDPROC
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Loop, 9 ; loop 9 times
|
||||
{
|
||||
output .= A_Index ; append the index of the current loop to the output var
|
||||
If (A_Index <> 9) ; if it isn't the 9th iteration of the loop
|
||||
output .= ", " ; append ", " to the output var
|
||||
}
|
||||
MsgBox, %output%
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
DIM i AS Integer
|
||||
|
||||
FOR i=1 TO 10
|
||||
PRINT i;
|
||||
IF i=10 THEN EXIT FOR
|
||||
PRINT ", ";
|
||||
NEXT i
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
10 FOR i=1 TO 10
|
||||
20 PRINT i;
|
||||
30 IF i=10 THEN GOTO 50
|
||||
40 PRINT ", ";
|
||||
50 NEXT i
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
FOR i% = 1 TO 10
|
||||
PRINT ; i% ;
|
||||
IF i% <> 10 PRINT ", ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
|
@ -0,0 +1 @@
|
|||
1+>::.9`#@_" ,",,
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"0" v
|
||||
1+>::"9"`#v_," ,",,>
|
||||
>"01",,@
|
||||
14
Task/Loops-N-plus-one-half/C++/loops-n-plus-one-half.cpp
Normal file
14
Task/Loops-N-plus-one-half/C++/loops-n-plus-one-half.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
for (int i = 1; ; i++)
|
||||
{
|
||||
std::cout << i;
|
||||
if (i == 10)
|
||||
break;
|
||||
std::cout << ", ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
11
Task/Loops-N-plus-one-half/C/loops-n-plus-one-half.c
Normal file
11
Task/Loops-N-plus-one-half/C/loops-n-plus-one-half.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i <= 10; i++) {
|
||||
printf("%d", i);
|
||||
printf(i == 10 ? "\n" : ", ");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
10
Task/Loops-N-plus-one-half/Clojure/loops-n-plus-one-half.clj
Normal file
10
Task/Loops-N-plus-one-half/Clojure/loops-n-plus-one-half.clj
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
; Functional version
|
||||
(apply str (interpose ", " (range 1 11)))
|
||||
|
||||
; Imperative version
|
||||
(loop [n 1]
|
||||
(printf "%d" n)
|
||||
(if (< n 10)
|
||||
(do
|
||||
(print ", ")
|
||||
(recur (inc n)))))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
# Loop plus half. This code shows how to break out of a loop early
|
||||
# on the last iteration. For the contrived example, there are better
|
||||
# ways to generate a comma-separated list, of course.
|
||||
start = 1
|
||||
end = 10
|
||||
s = ''
|
||||
for i in [start..end]
|
||||
# the top half of the loop executes every time
|
||||
s += i
|
||||
break if i == end
|
||||
# the bottom half of the loop is skipped for the last value
|
||||
s += ', '
|
||||
console.log s
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<cfloop index = "i" from = "1" to = "10">
|
||||
#i#
|
||||
<cfif i EQ 10>
|
||||
<cfbreak />
|
||||
</cfif>
|
||||
,
|
||||
</cfloop>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<cfscript>
|
||||
for( i = 1; i <= 10; i++ ) //note: the ++ notation works only on version 8 up, otherwise use i=i+1
|
||||
{
|
||||
writeOutput( i );
|
||||
|
||||
if( i == 10 )
|
||||
{
|
||||
break;
|
||||
}
|
||||
writeOutput( ", " );
|
||||
}
|
||||
</cfscript>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(loop for i from 1 below 10 do
|
||||
(princ i) (princ ", ")
|
||||
finally (princ i))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(loop for i from 1 upto 10 do
|
||||
(princ i)
|
||||
(if (= i 10) (return))
|
||||
(princ ", "))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(format t "~{~a~^, ~}" (loop for i from 1 to 10 collect i))
|
||||
12
Task/Loops-N-plus-one-half/D/loops-n-plus-one-half-1.d
Normal file
12
Task/Loops-N-plus-one-half/D/loops-n-plus-one-half-1.d
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
for (int i = 1; ; i++) {
|
||||
write(i);
|
||||
if (i >= 10)
|
||||
break;
|
||||
write(", ");
|
||||
}
|
||||
|
||||
writeln();
|
||||
}
|
||||
5
Task/Loops-N-plus-one-half/D/loops-n-plus-one-half-2.d
Normal file
5
Task/Loops-N-plus-one-half/D/loops-n-plus-one-half-2.d
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import std.stdio, std.range, std.algorithm, std.conv, std.string;
|
||||
|
||||
void main() {
|
||||
iota(1, 11).map!text().join(", ").writeln();
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
var i : Integer;
|
||||
|
||||
for i := 1 to 10 do begin
|
||||
Print(i);
|
||||
if i < 10 then
|
||||
Print(', ');
|
||||
end;
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
program LoopsNPlusOneHalf;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
i: integer;
|
||||
const
|
||||
MAXVAL = 10;
|
||||
begin
|
||||
for i := 1 to MAXVAL do
|
||||
begin
|
||||
Write(i);
|
||||
if i < MAXVAL then
|
||||
Write(', ');
|
||||
end;
|
||||
Writeln;
|
||||
end.
|
||||
7
Task/Loops-N-plus-one-half/E/loops-n-plus-one-half-1.e
Normal file
7
Task/Loops-N-plus-one-half/E/loops-n-plus-one-half-1.e
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
var i := 1
|
||||
while (true) {
|
||||
print(i)
|
||||
if (i >= 10) { break }
|
||||
print(", ")
|
||||
i += 1
|
||||
}
|
||||
11
Task/Loops-N-plus-one-half/E/loops-n-plus-one-half-2.e
Normal file
11
Task/Loops-N-plus-one-half/E/loops-n-plus-one-half-2.e
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var i := 1
|
||||
__loop(fn {
|
||||
print(i)
|
||||
if (i >= 10) {
|
||||
false
|
||||
} else {
|
||||
print(", ")
|
||||
i += 1
|
||||
true
|
||||
}
|
||||
})
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for i = 1 to 10 do
|
||||
printf(1, "%g", {i})
|
||||
if i < 10 then
|
||||
puts(1, ", ")
|
||||
end if
|
||||
end for
|
||||
|
|
@ -0,0 +1 @@
|
|||
1[$9>~][$.", "1+]#.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
: print-comma-list ( n -- )
|
||||
[ [1,b] ] keep '[
|
||||
[ number>string write ]
|
||||
[ _ = [ ", " write ] unless ] bi
|
||||
] each nl ;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
for (Int i := 1; i <= 10; i++)
|
||||
{
|
||||
Env.cur.out.writeObj (i)
|
||||
if (i == 10) break
|
||||
Env.cur.out.writeChars (", ")
|
||||
}
|
||||
Env.cur.out.printLine ("")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
: comma-list ( n -- )
|
||||
dup 1 ?do i 1 .r ." , " loop
|
||||
. ;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
: comma-list ( n -- )
|
||||
dup 1+ 1 do
|
||||
i 1 .r
|
||||
dup i = if leave then \ or DROP UNLOOP EXIT to exit loop and the function
|
||||
[char] , emit space
|
||||
loop drop ;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
: comma-list ( n -- )
|
||||
1
|
||||
begin dup 1 .r
|
||||
2dup <>
|
||||
while ." , " 1+
|
||||
repeat 2drop ;
|
||||
49
Task/Loops-N-plus-one-half/Fortran/loops-n-plus-one-half-1.f
Normal file
49
Task/Loops-N-plus-one-half/Fortran/loops-n-plus-one-half-1.f
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
C WARNING: This program is not valid ANSI FORTRAN 77 code. It uses
|
||||
C two nonstandard characters on the lines labelled 5001 and 5002.
|
||||
C Many F77 compilers should be okay with it, but it is *not*
|
||||
C standard.
|
||||
PROGRAM LOOPPLUSONEHALF
|
||||
INTEGER I, TEN
|
||||
C I'm setting a parameter to distinguish from the label 10.
|
||||
PARAMETER (TEN = 10)
|
||||
|
||||
DO 10 I = 1, TEN
|
||||
C Write the number only.
|
||||
WRITE (*,5001) I
|
||||
|
||||
C If we are on the last one, stop here. This will make this test
|
||||
C every iteration, which can slow your program down a little. If
|
||||
C you want to speed this up at the cost of your own convenience,
|
||||
C you could loop only to nine, and handle ten on its own after
|
||||
C the loop is finished. If you don't care, power to you.
|
||||
IF (I .EQ. TEN) GOTO 10
|
||||
|
||||
C Append a comma to the number.
|
||||
WRITE (*,5002) ','
|
||||
10 CONTINUE
|
||||
|
||||
C Always finish with a newline. This programmer hates it when a
|
||||
C program does not end its output with a newline.
|
||||
WRITE (*,5000) ''
|
||||
STOP
|
||||
|
||||
5000 FORMAT (A)
|
||||
|
||||
C Standard FORTRAN 77 is completely incapable of completing a
|
||||
C WRITE statement without printing a newline. This program would
|
||||
C be much more difficult (i.e. impossible) to write in the ANSI
|
||||
C standard, without cheating and saying something like:
|
||||
C
|
||||
C WRITE (*,*) '1, 2, 3, 4, 5, 6, 7, 8, 9, 10'
|
||||
C
|
||||
C The dollar sign at the end of the format is a nonstandard
|
||||
C character. It tells the compiler not to print a newline. If you
|
||||
C are actually using FORTRAN 77, you should figure out what your
|
||||
C particular compiler accepts. If you are actually using Fortran
|
||||
C 90 or later, you should replace this line with the commented
|
||||
C line that follows it.
|
||||
5001 FORMAT (I3, $)
|
||||
5002 FORMAT (A, $)
|
||||
C5001 FORMAT (T3, ADVANCE='NO')
|
||||
C5001 FORMAT (A, ADVANCE='NO')
|
||||
END
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
i = 1
|
||||
do
|
||||
write(*, '(I0)', advance='no') i
|
||||
if ( i == 10 ) exit
|
||||
write(*, '(A)', advance='no') ', '
|
||||
i = i + 1
|
||||
end do
|
||||
write(*,*)
|
||||
8
Task/Loops-N-plus-one-half/GML/loops-n-plus-one-half.gml
Normal file
8
Task/Loops-N-plus-one-half/GML/loops-n-plus-one-half.gml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
str = ""
|
||||
for(i = 1; i <= 10; i += 1)
|
||||
{
|
||||
str += string(i)
|
||||
if(i != 10)
|
||||
str += ", "
|
||||
}
|
||||
show_message(str)
|
||||
14
Task/Loops-N-plus-one-half/Go/loops-n-plus-one-half.go
Normal file
14
Task/Loops-N-plus-one-half/Go/loops-n-plus-one-half.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
for i := 1; ; i++ {
|
||||
fmt.Print(i)
|
||||
if i == 10 {
|
||||
fmt.Println("")
|
||||
break
|
||||
}
|
||||
fmt.Print(", ")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
for(i in (1..10)) {
|
||||
print i
|
||||
if (i == 10) break
|
||||
print ', '
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
loop :: IO ()
|
||||
loop = mapM_ action [1 .. 10]
|
||||
where action n = do
|
||||
putStr $ show n
|
||||
putStr $ if n == 10 then "\n" else ", "
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DO i = 1, 10
|
||||
WRITE(APPend) i
|
||||
IF(i < 10) WRITE(APPend) ", "
|
||||
ENDDO
|
||||
|
|
@ -0,0 +1 @@
|
|||
print,indgen(10)+1,format='(10(i,:,","))'
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for i=1,10 do begin
|
||||
print,i,format='($,i)'
|
||||
if i lt 10 then print,",",format='($,a)'
|
||||
endfor
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
for i=1,10 do begin
|
||||
print,i,format='($,i)'
|
||||
if i eq 10 then break
|
||||
print,",",format='($,a)'
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
procedure main()
|
||||
every writes(i := 1 to 10) do
|
||||
if i = 10 then break write()
|
||||
else writes(", ")
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
every writes(c := "",1 to 10) do c := ","
|
||||
14
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-1.j
Normal file
14
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-1.j
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
output=: verb define
|
||||
buffer=: buffer,y
|
||||
)
|
||||
|
||||
loopy=: verb define
|
||||
buffer=: ''
|
||||
for_n. 1+i.10 do.
|
||||
output ":n
|
||||
if. n<10 do.
|
||||
output ', '
|
||||
end.
|
||||
end.
|
||||
smoutput buffer
|
||||
)
|
||||
2
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-2.j
Normal file
2
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
loopy 0
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
2
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-3.j
Normal file
2
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-3.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
;}.,(', ' ; ":)&> 1+i.10
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
3
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-4.j
Normal file
3
Task/Loops-N-plus-one-half/J/loops-n-plus-one-half-4.j
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
commaAnd=: ":&.> ;@,. -@# {. (<;._1 '/ and /') ,~ (<', ') #~ #
|
||||
commaAnd i.5
|
||||
0, 1, 2, 3 and 4
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
public static void main(String[] args) {
|
||||
for (int i = 1; ; i++) {
|
||||
System.out.print(i);
|
||||
if (i == 10)
|
||||
break;
|
||||
System.out.print(", ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
function loop_plus_half(start, end) {
|
||||
var str = '',
|
||||
i;
|
||||
for (i = start; i <= end; i += 1) {
|
||||
str += i;
|
||||
if (i === end) {
|
||||
break;
|
||||
}
|
||||
str += ', ';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
alert(loop_plus_half(1, 10));
|
||||
3
Task/Loops-N-plus-one-half/K/loops-n-plus-one-half-1.k
Normal file
3
Task/Loops-N-plus-one-half/K/loops-n-plus-one-half-1.k
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
p:{`0:$x} / output
|
||||
i:1;do[10;p[i];p[:[i<10;", "]];i+:1];p@"\n"
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
2
Task/Loops-N-plus-one-half/K/loops-n-plus-one-half-2.k
Normal file
2
Task/Loops-N-plus-one-half/K/loops-n-plus-one-half-2.k
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
10 {p@x;p@:[x<10;", ";"\n"];x+1}\1;
|
||||
{p@x;p@:[x<10;", ";"\n"];x+1}'1+!10; /variant
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
: , dup ", " 2 compress "" join ;
|
||||
1 do dup 10 != if dup , . 1 + else . break then loop
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
: 2string 2 compress "" join ;
|
||||
: , dup 10 != if ", " 2string then ;
|
||||
1 10 "dup , . 1+" times
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for i =1 to 10
|
||||
print i;
|
||||
if i =10 then exit for
|
||||
print ", ";
|
||||
next i
|
||||
end
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
Section Header
|
||||
|
||||
+ name := LOOP_AND_HALF;
|
||||
|
||||
Section Public
|
||||
|
||||
- main <- (
|
||||
+ i : INTEGER;
|
||||
|
||||
i := 1;
|
||||
{
|
||||
i.print;
|
||||
i = 10
|
||||
}.until_do {
|
||||
", ".print;
|
||||
i := i + 1;
|
||||
};
|
||||
'\n'.print;
|
||||
);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
to comma.list :n
|
||||
repeat :n-1 [type repcount type "|, |]
|
||||
print :n
|
||||
end
|
||||
|
||||
comma.list 10
|
||||
5
Task/Loops-N-plus-one-half/Lua/loops-n-plus-one-half.lua
Normal file
5
Task/Loops-N-plus-one-half/Lua/loops-n-plus-one-half.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
for i = 1, 10 do
|
||||
io.write(i)
|
||||
if i == 10 then break end
|
||||
io.write", "
|
||||
end
|
||||
10
Task/Loops-N-plus-one-half/M4/loops-n-plus-one-half.m4
Normal file
10
Task/Loops-N-plus-one-half/M4/loops-n-plus-one-half.m4
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
define(`break',
|
||||
`define(`ulim',llim)')
|
||||
define(`for',
|
||||
`ifelse($#,0,``$0'',
|
||||
`define(`ulim',$3)`'define(`llim',$2)`'ifelse(ifelse($3,`',1,
|
||||
`eval($2<=$3)'),1,
|
||||
`pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),ulim,`$4')')')')
|
||||
|
||||
for(`x',`1',`',
|
||||
`x`'ifelse(x,10,`break',`, ')')
|
||||
|
|
@ -0,0 +1 @@
|
|||
printf('%i, ',1:9); printf('%i\n',10);
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for k=1:10,
|
||||
printf('%i', k);
|
||||
if k==10, break; end;
|
||||
printf(', ');
|
||||
end;
|
||||
printf('\n');
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for i in 1 to 10 do
|
||||
(
|
||||
format "%" i
|
||||
if i == 10 then exit
|
||||
format "%" ", "
|
||||
)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
LOOPHALF
|
||||
NEW I
|
||||
FOR I=1:1:10 DO
|
||||
.WRITE I
|
||||
.IF I'=10 WRITE ", "
|
||||
QUIT
|
||||
;Alternate
|
||||
NEW I FOR I=1:1:10 WRITE I WRITE:I'=10 ", "
|
||||
KILL I QUIT
|
||||
11
Task/Loops-N-plus-one-half/Make/loops-n-plus-one-half.make
Normal file
11
Task/Loops-N-plus-one-half/Make/loops-n-plus-one-half.make
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
NEXT=`expr $* + 1`
|
||||
MAX=10
|
||||
RES=1
|
||||
|
||||
all: 1-n;
|
||||
|
||||
$(MAX)-n:
|
||||
@echo $(RES)
|
||||
|
||||
%-n:
|
||||
@-make -f loop.mk $(NEXT)-n MAX=$(MAX) RES=$(RES),$(NEXT)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
i = 1; s = "";
|
||||
While[True,
|
||||
s = s <> ToString@i;
|
||||
If[i == 10, Break[]];
|
||||
s = s <> ",";
|
||||
i++;
|
||||
]
|
||||
s
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
last := 10;
|
||||
string s; s := "";
|
||||
for i = 1 upto last:
|
||||
s := s & decimal i;
|
||||
if i <> last: s := s & ", " fi;
|
||||
endfor
|
||||
message s;
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
MODULE Loop EXPORTS Main;
|
||||
|
||||
IMPORT IO, Fmt;
|
||||
|
||||
VAR i := 1;
|
||||
|
||||
BEGIN
|
||||
LOOP
|
||||
IO.Put(Fmt.Int(i));
|
||||
IF i = 10 THEN EXIT; END;
|
||||
IO.Put(", ");
|
||||
i := i + 1;
|
||||
END;
|
||||
IO.Put("\n");
|
||||
END Loop.
|
||||
7
Task/Loops-N-plus-one-half/PHP/loops-n-plus-one-half.php
Normal file
7
Task/Loops-N-plus-one-half/PHP/loops-n-plus-one-half.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
for ($i = 1; $i <= 11; $i++) {
|
||||
echo $i;
|
||||
if ($i == 10)
|
||||
break;
|
||||
echo ', ';
|
||||
}
|
||||
echo "\n";
|
||||
6
Task/Loops-N-plus-one-half/Perl/loops-n-plus-one-half.pl
Normal file
6
Task/Loops-N-plus-one-half/Perl/loops-n-plus-one-half.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
foreach my $i (1..10) {
|
||||
print $i;
|
||||
last if $i == 10;
|
||||
print ', ';
|
||||
}
|
||||
print "\n";
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(for N 10
|
||||
(prin N)
|
||||
(T (= N 10))
|
||||
(prin ", ") )
|
||||
|
|
@ -0,0 +1 @@
|
|||
print ( ', '.join(str(i+1) for i in range(10)) )
|
||||
13
Task/Loops-N-plus-one-half/Python/loops-n-plus-one-half-2.py
Normal file
13
Task/Loops-N-plus-one-half/Python/loops-n-plus-one-half-2.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
>>> from sys import stdout
|
||||
>>> write = stdout.write
|
||||
>>> n, i = 10, 1
|
||||
>>> while True:
|
||||
write(i)
|
||||
i += 1
|
||||
if i > n:
|
||||
break
|
||||
write(', ')
|
||||
|
||||
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
>>>
|
||||
1
Task/Loops-N-plus-one-half/R/loops-n-plus-one-half-1.r
Normal file
1
Task/Loops-N-plus-one-half/R/loops-n-plus-one-half-1.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
paste(1:10, collapse=", ")
|
||||
10
Task/Loops-N-plus-one-half/R/loops-n-plus-one-half-2.r
Normal file
10
Task/Loops-N-plus-one-half/R/loops-n-plus-one-half-2.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
for(i in 1:10)
|
||||
{
|
||||
cat(i)
|
||||
if(i==10)
|
||||
{
|
||||
cat("\n")
|
||||
break
|
||||
}
|
||||
cat(", ")
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/*REXX program to display: 1,2,3,4,5,6,7,8,9,10 */
|
||||
|
||||
do j=1 to 10
|
||||
call charout ,j /*write the DO loop index (no LF)*/
|
||||
if j<10 then call charout ,"," /*append a comma for 1-digit nums*/
|
||||
end /*j*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
/*REXX program to display: 1,2,3,4,5,6,7,8,9,10 */
|
||||
|
||||
do j=1 for 10 /*using FOR is faster than TO.*/
|
||||
call charout ,j || left(',',j<10) /*show J, maybe append a comma.*/
|
||||
end /*j*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
6
Task/Loops-N-plus-one-half/Ruby/loops-n-plus-one-half.rb
Normal file
6
Task/Loops-N-plus-one-half/Ruby/loops-n-plus-one-half.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
for i in 1..10 do
|
||||
print i
|
||||
break if i == 10
|
||||
print ", "
|
||||
end
|
||||
puts
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
@\>@\>@\>+++++++++<!/+. >-?\# digit and loop test
|
||||
| | \@@@+@+++++# \>>.<.<</ comma and space
|
||||
| \@@+@@+++++#
|
||||
\@@@@=++++#
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(call-with-current-continuation
|
||||
(lambda (esc)
|
||||
(do ((i 1 (+ 1 i))) (#f)
|
||||
(display i)
|
||||
(if (= i 10) (esc (newline)))
|
||||
(display ", "))))
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(let loop ((i 0))
|
||||
(display i)
|
||||
(if (= i 10)
|
||||
(newline)
|
||||
(begin
|
||||
(display ", ")
|
||||
(loop (+ 1 i)))))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
for {set i 1; set end 10} true {incr i} {
|
||||
puts -nonewline $i
|
||||
if {$i >= $end} break
|
||||
puts -nonewline ", "
|
||||
}
|
||||
puts ""
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
proc range {from to} {
|
||||
set result {}
|
||||
for {set i $from} {$i <= $to} {incr i} {
|
||||
lappend result $i
|
||||
}
|
||||
return $i
|
||||
}
|
||||
|
||||
puts [join [range 1 10] ", "] ;# ==> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||
Loading…
Add table
Add a link
Reference in a new issue