Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
category:
- Simple
from: http://rosettacode.org/wiki/Loops/N_plus_one_half
note: Iteration

View file

@ -0,0 +1,32 @@
Quite often one needs loops which, in the last iteration, execute only part of the loop body.
;Goal:
Demonstrate the best way to do this.
;Task:
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.
;Related tasks:
*   [[Loop over multiple arrays simultaneously]]
*   [[Loops/Break]]
*   [[Loops/Continue]]
*   [[Loops/Do-while]]
*   [[Loops/Downward for]]
*   [[Loops/For]]
*   [[Loops/For with a specified step]]
*   [[Loops/Foreach]]
*   [[Loops/Increment loop index within loop body]]
*   [[Loops/Infinite]]
*   [[Loops/N plus one half]]
*   [[Loops/Nested]]
*   [[Loops/While]]
*   [[Loops/with multiple ranges]]
*   [[Loops/Wrong ranges]]
<br><br>

View file

@ -0,0 +1,4 @@
L(i) 1..10
print(i, end' )
I !L.last_iteration
print(, , end' )

View file

@ -0,0 +1,23 @@
* Loops/N plus one half 13/08/2015
LOOPHALF CSECT USING LOOPHALF,R12
LR R12,R15
BEGIN LA R3,MVC
SR R5,R5
LA R6,1
LA R7,10
LOOPI BXH R5,R6,ELOOPI for i=1 to 10
XDECO R5,XDEC
MVC 0(4,R3),XDEC+8
LA R3,4(R3)
CH R5,=H'10'
BNL NEXTI
MVC 0(2,R3),=C', '
LA R3,2(R3)
NEXTI B LOOPI next i
ELOOPI XPRNT MVC,80
XR R15,R15
BR R14
MVC DC CL80' '
XDEC DS CL12
YREGS
END LOOPHALF

View file

@ -0,0 +1,24 @@
moveq #0,d0
move.w #1,d1 ;ABCD can't use an immediate operand
move.w #10-1,d2
loop:
abcd d1,d0
move.l d0,-(sp)
jsr printhex
move.l (sp)+,d0
cmp.b #$10,d0 ;we use hex 10 since this is binary-coded decimal
beq exitEarly
move.l d0,-(sp)
move.b #',',D0 ;PrintChar uses D0 as input
jsr PrintChar
move.b #' ',D0
jsr PrintChar
move.l (sp)+,d0
DBRA d2,loop
exitEarly:
; include "X:\SrcGEN\testModule.asm"
jmp *

View file

@ -0,0 +1,54 @@
.model small
.stack 1024
.data ;no data needed
.code
start:
mov ax,0000h
mov cx,0FFFFh ;this value doesn't matter as long as it's greater than decimal 10.
repeatPrinting:
add ax,1 ;it was easier to start at zero and add here than to start at 1 and add after printing.
aaa ;ascii adjust for addition, corrects 0009h+1 from 000Ah to 0100h
call PrintBCD_IgnoreLeadingZeroes
cmp ax,0100h ;does AX = BCD 10?
je exitLoopEarly ;if so, we're done now. Don't finish the loop.
push ax
mov dl,"," ;print a comma
mov ah,02h
int 21h
mov dl,20h ;print a blank space
mov ah,02h
int 21h
pop ax
loop repeatPrinting
exitLoopEarly:
mov ax,4C00h
int 21h ;return to DOS
PrintBCD_IgnoreLeadingZeroes:
push ax
cmp ah,0
jz skipLeadingZero
or ah,30h ;converts a binary-coded-decimal value to an ASCII numeral
push dx
push ax
mov al,ah
mov ah,0Eh
int 10h ;prints AL to screeen
pop ax
pop dx
skipLeadingZero:
or al,30h
push dx
push ax
mov ah,0Eh
int 10h ;prints AL to screen
pop ax
pop dx
pop ax
ret
end start ;EOF

View file

@ -0,0 +1,65 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program loopnplusone64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessResult: .asciz "@" // message result
szMessComma: .asciz ", "
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sZoneConv: .skip 24
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: // entry of program
mov x20,1 // loop counter
1: // begin loop
mov x0,x20
ldr x1,qAdrsZoneConv // display value
bl conversion10 // decimal conversion
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv // display value
bl strInsertAtCharInc // insert result at @ character
bl affichageMess // display message
ldr x0,qAdrszMessComma
bl affichageMess // display comma
add x20,x20,1 // increment counter
cmp x20,10 // end ?
blt 1b // no ->begin loop one
mov x0,x20
ldr x1,qAdrsZoneConv // display value
bl conversion10 // decimal conversion
ldr x0,qAdrszMessResult
ldr x1,qAdrsZoneConv // display value
bl strInsertAtCharInc // insert result at @ character
bl affichageMess // display message
ldr x0,qAdrszCarriageReturn
bl affichageMess // display return line
100: // standard end of the program
mov x0,0 // return code
mov x8,EXIT // request to exit program
svc 0 // perform the system call
qAdrsZoneConv: .quad sZoneConv
qAdrszMessResult: .quad szMessResult
qAdrszMessComma: .quad szMessComma
qAdrszCarriageReturn: .quad szCarriageReturn
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -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))))))

View file

@ -0,0 +1,8 @@
'BEGIN'
'COMMENT' Loops N plus one half - Algol60 - 20/06/2018;
'INTEGER' I;
'FOR' I:=1 'STEP' 1 'UNTIL' 10 'DO' 'BEGIN'
OUTINTEGER(1,I);
'IF' I 'NOTEQUAL' 10 'THEN' OUTSTRING(1,'(', ')')
'END'
'END'

View file

@ -0,0 +1,8 @@
FOR i WHILE
print(whole(i, -2));
# WHILE # i < 10 DO
print(", ")
OD;
print(new line)

View file

@ -0,0 +1,8 @@
FOR i TO 10 DO
print(whole(i, -2));
IF i < 10 THEN
print(", ")
FI
OD;
print(new line)

View file

@ -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)

View file

@ -0,0 +1,14 @@
begin
integer i;
i := 0;
while
begin
i := i + 1;
writeon( i );
i < 10
end
do
begin
writeon( "," )
end
end.

View file

@ -0,0 +1,127 @@
/* ARM assembly Raspberry PI */
/* program loopnplusone.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ WRITE, 4 @ Linux syscall
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessResult: .ascii "" @ message result
sMessValeur: .fill 11, 1, ' '
szMessComma: .asciz ","
szCarriageReturn: .asciz "\n"
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
/*********************************/
/* code section */
/*********************************/
.text
.global main
main: @ entry of program
mov r4,#1 @ loop counter
1: @ begin loop
mov r0,r4
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ decimal conversion
ldr r0,iAdrszMessResult
bl affichageMess @ display message
ldr r0,iAdrszMessComma
bl affichageMess @ display comma
add r4,#1 @ increment counter
cmp r4,#10 @ end ?
blt 1b @ no ->begin loop one
mov r0,r4
ldr r1,iAdrsMessValeur @ display value
bl conversion10 @ decimal conversion
ldr r0,iAdrszMessResult
bl affichageMess @ display message
ldr r0,iAdrszCarriageReturn
bl affichageMess @ display return line
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
svc #0 @ perform the system call
iAdrsMessValeur: .int sMessValeur
iAdrszMessResult: .int szMessResult
iAdrszMessComma: .int szMessComma
iAdrszCarriageReturn: .int szCarriageReturn
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registres
mov r2,#0 @ counter length
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call systeme
pop {r0,r1,r2,r7,lr} @ restaur registers */
bx lr @ return
/******************************************************************/
/* Converting a register to a decimal */
/******************************************************************/
/* r0 contains value and r1 address area */
.equ LGZONECAL, 10
conversion10:
push {r1-r4,lr} @ save registers
mov r3,r1
mov r2,#LGZONECAL
1: @ start loop
bl divisionpar10 @ r0 <- dividende. quotient ->r0 reste -> r1
add r1,#48 @ digit
strb r1,[r3,r2] @ store digit on area
sub r2,#1 @ previous position
cmp r0,#0 @ stop if quotient = 0
bne 1b @ else loop
@ end replaces digit in front of area
mov r4,#0
2:
ldrb r1,[r3,r2]
strb r1,[r3,r4] @ store in area begin
add r4,#1
add r2,#1 @ previous position
cmp r2,#LGZONECAL @ end
ble 2b @ loop
mov r1,#0 @ final zero
strb r1,[r3,r4]
100:
pop {r1-r4,lr} @ restaur registres
bx lr @return
/***************************************************/
/* division par 10 signé */
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
/* and http://www.hackersdelight.org/ */
/***************************************************/
/* r0 dividende */
/* r0 quotient */
/* r1 remainder */
divisionpar10:
/* r0 contains the argument to be divided by 10 */
push {r2-r4} @ save registers */
mov r4,r0
mov r3,#0x6667 @ r3 <- magic_number lower
movt r3,#0x6666 @ r3 <- magic_number upper
smull r1, r2, r3, r0 @ r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0)
mov r2, r2, ASR #2 @ r2 <- r2 >> 2
mov r1, r0, LSR #31 @ r1 <- r0 >> 31
add r0, r2, r1 @ r0 <- r2 + r1
add r2,r0,r0, lsl #2 @ r2 <- r0 * 5
sub r1,r4,r2, lsl #1 @ r1 <- r4 - (r2 * 2) = r4 - (r0 * 10)
pop {r2-r4}
bx lr @ return

View file

@ -0,0 +1,7 @@
REM Loops/N plus one half
FOR I = 1 TO 9
PRINT I;
PRINT ",";
NEXT I
PRINT 10
END

View file

@ -0,0 +1 @@
$ awk 'BEGIN{for(i=1;i<=10;i++){printf i;if(i<10)printf ", "};print}'

View file

@ -0,0 +1,8 @@
BEGIN {
n=10
for(i=1;i<=n;i++) {
printf i;
if(i<n) printf ", "
}
print
}

View file

@ -0,0 +1,12 @@
PROC Main()
BYTE i=[1]
DO
PrintB(i)
IF i=10 THEN
EXIT
FI
Print(", ")
i==+1
OD
RETURN

View file

@ -0,0 +1,11 @@
with Ada.Text_IO;
procedure LoopsAndHalf is
begin
for i in 1 .. 10 loop
Ada.Text_IO.put (i'Img);
exit when i = 10;
Ada.Text_IO.put (",");
end loop;
Ada.Text_IO.new_line;
end LoopsAndHalf;

View file

@ -0,0 +1,12 @@
integer i;
i = 0;
while (1) {
i += 1;
o_integer(i);
if (i == 10) {
break;
}
o_text(", ");
}
o_text("\n");

View file

@ -0,0 +1,8 @@
PROC main()
DEF i
FOR i := 1 TO 10
WriteF('\d', i)
EXIT i = 10
WriteF(', ')
ENDFOR
ENDPROC

View file

@ -0,0 +1,3 @@
10 FOR I = 1 TO 10
20 PRINT I;
30 IF I < 10 THEN PRINT ", "; : NEXT I

View file

@ -0,0 +1,20 @@
IT'S SHOWTIME
HEY CHRISTMAS TREE n
YOU SET US UP @NO PROBLEMO
HEY CHRISTMAS TREE lessThanTen
YOU SET US UP @NO PROBLEMO
STICK AROUND lessThanTen
TALK TO THE HAND n
GET TO THE CHOPPER lessThanTen
HERE IS MY INVITATION 10
LET OFF SOME STEAM BENNET n
ENOUGH TALK
BECAUSE I'M GOING TO SAY PLEASE lessThanTen
TALK TO THE HAND ", "
YOU HAVE NO RESPECT FOR LOGIC
GET TO THE CHOPPER n
HERE IS MY INVITATION n
GET UP @NO PROBLEMO
ENOUGH TALK
CHILL
YOU HAVE BEEN TERMINATED

View file

@ -0,0 +1 @@
print join.with:", " map 1..10 => [to :string]

View file

@ -0,0 +1,4 @@
for(int i = 1; i <= 10; ++i) {
write(i, suffix=none);
if(i < 10) write(", ", suffix=none);
}

View file

@ -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%

View file

@ -0,0 +1,26 @@
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author: Alexander Alvonellos
Script Function:
Output a comma separated list from 1 to 10, and on the tenth iteration of the
output loop, only perform half of the loop.
#ce ----------------------------------------------------------------------------
Func doLoopIterative()
Dim $list = ""
For $i = 1 To 10 Step 1
$list = $list & $i
If($i = 10) Then ExitLoop
$list = $list & ", "
Next
return $list & @CRLF
EndFunc
Func main()
ConsoleWrite(doLoopIterative())
EndFunc
main()

View file

@ -0,0 +1,8 @@
For(I,1,10)
Disp I▶Dec
If I=10
Disp i
Else
Disp ","
End
End

View file

@ -0,0 +1,7 @@
DIM i AS Integer
FOR i=1 TO 10
PRINT USING "##"; i;
IF i=10 THEN EXIT FOR
PRINT ", ";
NEXT i

View file

@ -0,0 +1,6 @@
for i = 1 to 10
print i;
if i < 10 then print ", ";
next i
end

View file

@ -0,0 +1,5 @@
FOR i% = 1 TO 10
PRINT ; i% ;
IF i% <> 10 PRINT ", ";
NEXT
PRINT

View file

@ -0,0 +1,8 @@
PROCEDURE nAndAHalf
DIM i:INTEGER
FOR i:=1 TO 10
PRINT i;
EXITIF i=10 THEN ENDEXIT
PRINT ", ";
NEXT i
PRINT

View file

@ -0,0 +1,8 @@
while (1) {
print ++i
if (i == 10) {
print "\n"
break
}
print ", "
}

View file

@ -0,0 +1 @@
1+>::.9`#@_" ,",,

View file

@ -0,0 +1,2 @@
1+>::68*+,8`#v_" ,",,
@,,,,", 10"<

View file

@ -0,0 +1,6 @@
1:?i
& whl
' ( put$!i
& !i+1:~>10:?i
& put$", "
)

View file

@ -0,0 +1,12 @@
#include <iostream>
int main()
{
int i;
for (i = 1; i<=10 ; i++){
std::cout << i;
if (i < 10)
std::cout << ", ";
}
return 0;
}

View file

@ -0,0 +1,15 @@
using System;
class Program
{
static void Main(string[] args)
{
for (int i = 1; ; i++)
{
Console.Write(i);
if (i == 10) break;
Console.Write(", ");
}
Console.WriteLine();
}
}

View 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;
}

View file

@ -0,0 +1,27 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Loop-N-And-Half.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 99.
01 List PIC X(45).
PROCEDURE DIVISION.
PERFORM FOREVER
*> The list to display must be built up because using
*> DISPLAY adds an endline at the end automatically.
STRING FUNCTION TRIM(List) " " I INTO List
IF I = 10
EXIT PERFORM
END-IF
STRING FUNCTION TRIM(List) "," INTO List
ADD 1 TO I
END-PERFORM
DISPLAY List
GOBACK
.

View file

@ -0,0 +1,18 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. LOOP-1p5-NOADV.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 99 VALUE 1.
01 IDISP PIC Z9.
PROCEDURE DIVISION.
PERFORM FOREVER
MOVE I TO IDISP
DISPLAY FUNCTION TRIM(IDISP) WITH NO ADVANCING
IF I = 10
EXIT PERFORM
END-IF
DISPLAY ", " WITH NO ADVANCING
ADD 1 TO I
END-PERFORM.
STOP RUN.
END-PROGRAM.

View file

@ -0,0 +1,18 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. LOOP-1p5-NOADV-GOTO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 99 VALUE 1.
88 END-LIST VALUE 10.
01 I-OUT PIC Z9.
PROCEDURE DIVISION.
01-LOOP.
MOVE I TO I-OUT.
DISPLAY FUNCTION TRIM(I-OUT) WITH NO ADVANCING.
IF END-LIST GO TO 02-DONE.
DISPLAY ", " WITH NO ADVANCING.
ADD 1 TO I.
GO TO 01-LOOP.
02-DONE.
STOP RUN.
END-PROGRAM.

View file

@ -0,0 +1,17 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. LOOP-1p5-NOADV-VARY.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 I PIC 99 VALUE 1.
88 END-LIST VALUE 10.
01 I-OUT PIC Z9.
PROCEDURE DIVISION.
PERFORM WITH TEST AFTER VARYING I FROM 1 BY 1 UNTIL END-LIST
MOVE I TO I-OUT
DISPLAY FUNCTION TRIM(I-OUT) WITH NO ADVANCING
IF NOT END-LIST
DISPLAY ", " WITH NO ADVANCING
END-IF
END-PERFORM.
STOP RUN.
END-PROGRAM.

View file

@ -0,0 +1,2 @@
for i in 1..10 do
write(i, if i % 10 > 0 then ", " else "\n")

View file

@ -0,0 +1,6 @@
10 rem Loops/N plus one half
20 c$ = ""
30 for i = 1 to 10
40 print c$;str$(i);
50 c$ = ", "
60 next i

View 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)))))

View file

@ -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

View file

@ -0,0 +1,7 @@
<cfloop index = "i" from = "1" to = "10">
#i#
<cfif i EQ 10>
<cfbreak />
</cfif>
,
</cfloop>

View file

@ -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>

View file

@ -0,0 +1,3 @@
(loop for i from 1 below 10 do
(princ i) (princ ", ")
finally (princ i))

View file

@ -0,0 +1,4 @@
(loop for i from 1 upto 10 do
(princ i)
(if (= i 10) (return))
(princ ", "))

View file

@ -0,0 +1 @@
(format t "~{~a~^, ~}" (loop for i from 1 to 10 collect i))

View file

@ -0,0 +1,6 @@
(do ((i 1 (incf i))) ; Initialize to 1 and increment on every loop
((> i 10)) ; Break condition
(princ i) ; Print the iteration number
(when (= i 10) (go end)) ; Use the implicit tagbody and go to end tag when reach the last iteration
(princ ", ") ; Printing the comma is jumped by the go statement
end) ; The tag

View file

@ -0,0 +1,5 @@
(do ; Not exactly separate statements for the number and the comma
((i 1 (incf i))) ; Initialize to 1 and increment on every loop
((> i 9) (princ i)) ; Break condition when iteration is the last number, print it
(princ i) ; Print number statement
(princ ", ")) ; Print comma statement

View file

@ -0,0 +1,10 @@
include "cowgol.coh";
var i: uint8 := 1;
loop
print_i8(i);
if i == 10 then break; end if;
print(", ");
i := i + 1;
end loop;
print_nl();

View file

@ -0,0 +1,12 @@
import std.stdio;
void main() {
for (int i = 1; ; i++) {
write(i);
if (i >= 10)
break;
write(", ");
}
writeln();
}

View file

@ -0,0 +1,7 @@
void main() {
import std.stdio, std.range, std.algorithm, std.conv, std.string;
iota(1, 11).map!text.join(", ").writeln;
// A simpler solution:
writefln("%(%d, %)", iota(1, 11));
}

View file

@ -0,0 +1,7 @@
var i : Integer;
for i := 1 to 10 do begin
Print(i);
if i < 10 then
Print(', ');
end;

View file

@ -0,0 +1,15 @@
String loopPlusHalf(start, end) {
var result = '';
for(int i = start; i <= end; i++) {
result += '$i';
if(i == end) {
break;
}
result += ', ';
}
return result;
}
void main() {
print(loopPlusHalf(1, 10));
}

View file

@ -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.

View file

@ -0,0 +1,11 @@
proc nonrec main() void:
byte i;
i := 1;
while
write(i);
i := i + 1;
i <= 10
do
write(", ")
od
corp

View file

@ -0,0 +1,7 @@
var i := 1
while (true) {
print(i)
if (i >= 10) { break }
print(", ")
i += 1
}

View file

@ -0,0 +1,11 @@
var i := 1
__loop(fn {
print(i)
if (i >= 10) {
false
} else {
print(", ")
i += 1
true
}
})

View file

@ -0,0 +1,41 @@
[ N and a half times loop
=======================
A program for the EDSAC
Works with Initial Orders 2 ]
T56K
GK
O16@
[ 1 ] T24@
A25@
A18@
U25@
S23@
E11@
O25@
O19@
O20@
G1@
[ 11 ] O18@
O17@
O21@
O22@
ZF
[ 16 ] #F
[ 17 ] PF
[ 18 ] QF
[ 19 ] NF
[ 20 ] !F
[ 21 ] @F
[ 22 ] &F
[ 23 ] JF
[ 24 ] PF
[ 25 ] PF
EZPF

View file

@ -0,0 +1,52 @@
[Loop-and-a-half for Rosetta Code.
EDSAC program, Initial Orders 2.]
T64K [load at location 64 (arbitrary choice)]
GK [set @ (theta) parameter]
[Constants]
[0] OF [digit 9]
[1] JF [to inc digit after subtracting 9]
[2] #F [figures mode]
[3] !F [space]
[4] NF [comma (in figures mode)]
[5] @F [carriage return]
[6] &F [line feed]
[Variable]
[7] PF [current digit]
[First subroutine to print digits 0..9]
[8] A3F T20@ [plant return link as usual]
T7@ [digit := 0]
[11] O7@ [loop: print digit]
A7@ S@ [is digit 9?]
E20@ [if so, jump to exit]
O4@ O3@ [print comma and space]
A1@ [inc digit in acc]
T7@ [update digit in store]
E11@ [always loop back]
[20] ZF [(planted) return to caller with acc = 0]
[Second subroutine to print digits 0..9
Instead of saying "print a comma after each digit except the last"
it says "print a comma before each digit except the first".]
[21] A3F T33@ [plant return link as usual]
T7@ [digit := 0]
E29@ [jump into middle of loop]
[25] A1@ [loop: inc digit in acc]
T7@ [update digit in store]
O4@ O3@ [print comma and space]
[29] O7@ [print digit]
A7@ S@ [is digit 9?]
G25@ [if not, loop back]
[33] ZF [(planted) return to caller with acc = 0]
[Enter with acc = 0]
[34] O2@ [set teleprinter to figures]
A35@ G8@ [call first subroutine]
O5@ O6@ [print CR, LF]
A39@ G21@ [call second subroutine]
O5@ O6@ [print CR, LF]
O2@ [print dummy character to flush teleprinter buffer]
ZF [stop]
E34Z [define entry point]
PF [value of acc on entry (here = 0)]
[end]

View file

@ -0,0 +1,5 @@
FOR I=1 TO 10 DO
PRINT(I;)
EXIT IF I=10
PRINT(", ";)
END FOR

View file

@ -0,0 +1,6 @@
for i = 1 to 10
write i
if i < 10
write ", "
.
.

View file

@ -0,0 +1,9 @@
(string-delimiter "")
(for ((i (in-range 1 11))) (write i) #:break (= i 10) (write ","))
→ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10
;; or
(string-join (range 1 11) ",")
→ 1,2,3,4,5,6,7,8,9,10

View file

@ -0,0 +1,10 @@
defmodule Loops do
def n_plus_one_half([]), do: IO.puts ""
def n_plus_one_half([x]), do: IO.puts x
def n_plus_one_half([h|t]) do
IO.write "#{h}, "
n_plus_one_half(t)
end
end
Enum.to_list(1..10) |> Loops.n_plus_one_half

View file

@ -0,0 +1,14 @@
%% Implemented by Arjun Sunel
-module(loop).
-export([main/0]).
main() ->
for_loop(1).
for_loop(N) ->
if N < 10 ->
io:format("~p, ",[N] ),
for_loop(N+1);
true ->
io:format("~p\n",[N])
end.

View file

@ -0,0 +1,6 @@
for i = 1 to 10 do
printf(1, "%g", {i})
if i < 10 then
puts(1, ", ")
end if
end for

View file

@ -0,0 +1,10 @@
let rec print (lst : int list) =
match lst with
| hd :: [] ->
printf "%i " hd
| hd :: tl ->
printf "%i, " hd
print tl
| [] -> printf "\n"
print [1..10]

View file

@ -0,0 +1 @@
1[$9>~][$.", "1+]#.

View file

@ -0,0 +1,6 @@
#APPTYPE CONSOLE
For Dim i = 1 To 10
PRINT i;
IF i < 10 THEN PRINT ", ";
Next
PAUSE

View file

@ -0,0 +1,5 @@
: print-comma-list ( n -- )
[ [1,b] ] keep '[
[ number>string write ]
[ _ = [ ", " write ] unless ] bi
] each nl ;

View file

@ -0,0 +1,7 @@
for value = 1 to 10
formiddle
>> value
>> ", "
end
forlast: > value
end

View file

@ -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 ("")
}
}

View file

@ -0,0 +1,3 @@
: comma-list ( n -- )
dup 1 ?do i 1 .r ." , " loop
. ;

View file

@ -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 ;

View file

@ -0,0 +1,6 @@
: comma-list ( n -- )
1
begin dup 1 .r
2dup <>
while ." , " 1+
repeat 2drop ;

View file

@ -0,0 +1,5 @@
C Loops N plus one half - Fortran IV (1964)
INTEGER I
WRITE(6,301) (I,I=1,10)
301 FORMAT((I3,','))
END

View 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

View file

@ -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(*,*)

View file

@ -0,0 +1,9 @@
' FB 1.05.0 Win64
For i As Integer = 1 To 10
Print Str(i);
If i < 10 Then Print ", ";
Next
Print
Sleep

View file

@ -0,0 +1,5 @@
dim as string cm = ""
for i as ubyte = 1 to 10
print cm;str(i);
cm = ", "
next i

View file

@ -0,0 +1,11 @@
window 1
long i, num = 10
for i = 1 to num
print i;
if i = num then break
print @", ";
next i
HandleEvents

View file

@ -0,0 +1,9 @@
n := 10;
for i in [1 .. n] do
Print(i);
if i < n then
Print(", ");
else
Print("\n");
fi;
od;

View file

@ -0,0 +1,8 @@
str = ""
for(i = 1; i <= 10; i += 1)
{
str += string(i)
if(i != 10)
str += ", "
}
show_message(str)

View file

@ -0,0 +1,5 @@
10 C$ = ""
20 FOR I = 1 TO 10
30 PRINT C$;STR$(I);
40 C$=", "
50 NEXT I

View file

@ -0,0 +1,9 @@
Public Sub Main()
Dim siLoop As Short
For siLoop = 1 To 10
Print siLoop;
If siLoop <> 10 Then Print ", ";
Next
End

View 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(", ")
}
}

View file

@ -0,0 +1,5 @@
var out = System.out
for(i in 1..10) {
if(i > 1) out.print(", ")
out.print(i)
}

View file

@ -0,0 +1,5 @@
for(i in (1..10)) {
print i
if (i == 10) break
print ', '
}

View file

@ -0,0 +1,4 @@
main :: IO ()
main = forM_ [1 .. 10] $ \n -> do
putStr $ show n
putStr $ if n == 10 then "\n" else ", "

View file

@ -0,0 +1 @@
intercalate ", " (map show [1..10])

View file

@ -0,0 +1,2 @@
for (i in 1...11)
Sys.print('$i${i == 10 ? '\n' : ', '}');

View file

@ -0,0 +1,6 @@
for let i 1; i <= 10; i++
print i
if i = 10; break; endif
print ", "
endfor
println ""

View file

@ -0,0 +1,4 @@
DO i = 1, 10
WRITE(APPend) i
IF(i < 10) WRITE(APPend) ", "
ENDDO

View file

@ -0,0 +1,7 @@
U8 i, max = 10;
for (i = 1; i <= max; i++) {
Print("%d", i);
if (i == max) break;
Print(", ");
}
Print("\n");

View file

@ -0,0 +1 @@
print,indgen(10)+1,format='(10(i,:,","))'

Some files were not shown because too many files have changed in this diff Show more