Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Loops-For-with-a-specified-step/00-META.yaml
Normal file
5
Task/Loops-For-with-a-specified-step/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
from: http://rosettacode.org/wiki/Loops/For_with_a_specified_step
|
||||
note: Iteration
|
||||
22
Task/Loops-For-with-a-specified-step/00-TASK.txt
Normal file
22
Task/Loops-For-with-a-specified-step/00-TASK.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
;Task:
|
||||
Demonstrate a ''for-loop'' where the step-value is greater than one.
|
||||
|
||||
|
||||
;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>
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
L(i) (1..9).step(2)
|
||||
print(i)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
* Loops/For with a specified step 12/08/2015
|
||||
LOOPFORS CSECT
|
||||
USING LOOPFORS,R12
|
||||
LR R12,R15
|
||||
* == Algol style ================ test at the beginning
|
||||
LA R3,BUF idx=0
|
||||
LA R5,0 from 5 (from-step=0)
|
||||
LA R6,5 step 5
|
||||
LA R7,25 to 25
|
||||
LOOPI BXH R5,R6,ELOOPI for i=5 to 25 step 5
|
||||
XDECO R5,XDEC edit i
|
||||
MVC 0(4,R3),XDEC+8 output i
|
||||
LA R3,4(R3) idx=idx+4
|
||||
B LOOPI next i
|
||||
ELOOPI XPRNT BUF,80 print buffer
|
||||
BR R14
|
||||
BUF DC CL80' ' buffer
|
||||
XDEC DS CL12 temp for edit
|
||||
YREGS
|
||||
END LOOPFORS
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
* == Fortran style ============== test at the end
|
||||
LA R3,BUF idx=0
|
||||
LA R5,5 from 5
|
||||
LA R6,5 step 5
|
||||
LA R7,25 to 25
|
||||
LOOPJ XDECO R5,XDEC for j=5 to 25 step 5; edit j
|
||||
MVC 0(4,R3),XDEC+8 output j
|
||||
LA R3,4(R3) idx=idx+4
|
||||
BXLE R5,R6,LOOPJ next j
|
||||
XPRNT BUF,80 print buffer
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
* == Algol style ================ test at the beginning
|
||||
LA R3,BUF idx=0
|
||||
LA R5,5 from 5
|
||||
LA R6,5 step 5
|
||||
LA R7,25 to 25
|
||||
DO WHILE=(CR,R5,LE,R7) for i=5 to 25 step 5
|
||||
XDECO R5,XDEC edit i
|
||||
MVC 0(4,R3),XDEC+8 output i
|
||||
LA R3,4(R3) idx=idx+4
|
||||
AR R5,R6 i=i+step
|
||||
ENDDO , next i
|
||||
XPRNT BUF,80 print buffer
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
* == Fortran style ============== test at the end
|
||||
LA R3,BUF idx=0
|
||||
DO FROM=(R5,5),TO=(R7,25),BY=(R6,5) for i=5 to 25 step 5
|
||||
XDECO R5,XDEC edit i
|
||||
MVC 0(4,R3),XDEC+8 output i
|
||||
LA R3,4(R3) idx=idx+4
|
||||
ENDDO , next i
|
||||
XPRNT BUF,80 print buffer
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
define ArrayPointerLo $00 ;define some helpful labels.
|
||||
define ArrayPointerHi $01
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
setArray: ;Easy6502 doesn't let us define arbitrary bytes so the best option is to fill the range at runtime.
|
||||
lda #$10
|
||||
ldx #0
|
||||
loop_setArray:
|
||||
sta $1200,x
|
||||
clc
|
||||
adc #$10
|
||||
inx
|
||||
cpx #$08
|
||||
bcc loop_setArray
|
||||
; stores this sequence of hex values starting at $1200: $10 $20 $30 $40 $50 $60 $70 $80
|
||||
|
||||
ClearMem: ;clear $D000-$D0FF
|
||||
lda #0
|
||||
ldx #0
|
||||
loop_clearMem:
|
||||
sta $D000,x
|
||||
inx
|
||||
bne loop_clearMem
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; end of prep work, the real code begins here.
|
||||
|
||||
lda #$12 ;high byte of array address
|
||||
sta ArrayPointerHi
|
||||
lda #$00 ;low byte of array address
|
||||
sta ArrayPointerLo ;these are used to look up the array rather than hard-code it in.
|
||||
|
||||
|
||||
|
||||
ldx #$0E ;the loop counter, gets decremented twice per iteration to skip the odd addresses.
|
||||
ldy #7 ;the index into the source array.
|
||||
|
||||
;on the 6502 looping backwards is almost always faster.
|
||||
|
||||
loop_fill:
|
||||
lda (ArrayPointerLo),y ;loads from the array's base address, plus Y
|
||||
sta $D000,x ;store at $D000+X
|
||||
dey ;decrement array index
|
||||
dex
|
||||
dex ;decrement destination index twice
|
||||
bpl loop_fill ;if destination index equals #$FF, we are done.
|
||||
|
||||
brk ;end of program
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program loopstep64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
.equ MAXI, 20
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessResult: .asciz "Counter = @ \n" // message result
|
||||
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
mov x4,0 // init counter
|
||||
1: // begin loop
|
||||
mov x0,x4
|
||||
ldr x1,qAdrsZoneConv // display value
|
||||
bl conversion10 // call function with 2 parameter (x0,x1)
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at first @ character
|
||||
bl affichageMess // display message
|
||||
add x4,x4,2 // increment counter by 2
|
||||
cmp x4,MAXI //
|
||||
ble 1b // loop
|
||||
|
||||
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
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
BEGIN
|
||||
INTEGER I;
|
||||
FOR I := 1 STEP 3 UNTIL 19 DO
|
||||
WRITE( I );
|
||||
END
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
begin
|
||||
for i := 3 step 2 until 9 do write( i )
|
||||
end.
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program loopstep2.s */
|
||||
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1 @ Linux output console
|
||||
.equ EXIT, 1 @ Linux syscall
|
||||
.equ WRITE, 4 @ Linux syscall
|
||||
.equ MAXI, 20
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessResult: .ascii "Counter = " @ message result
|
||||
sMessValeur: .fill 12, 1, ' '
|
||||
.asciz "\n"
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: @ entry of program
|
||||
push {fp,lr} @ saves 2 registers
|
||||
mov r4,#0
|
||||
1: @ begin loop
|
||||
mov r0,r4
|
||||
ldr r1,iAdrsMessValeur @ display value
|
||||
bl conversion10 @ call function with 2 parameter (r0,r1)
|
||||
ldr r0,iAdrszMessResult
|
||||
bl affichageMess @ display message
|
||||
add r4,#2 @ increment counter by 2
|
||||
cmp r4,#MAXI @
|
||||
ble 1b @ loop
|
||||
|
||||
100: @ standard end of the program
|
||||
mov r0, #0 @ return code
|
||||
pop {fp,lr} @restaur 2 registers
|
||||
mov r7, #EXIT @ request to exit program
|
||||
svc #0 @ perform the system call
|
||||
|
||||
iAdrsMessValeur: .int sMessValeur
|
||||
iAdrszMessResult: .int szMessResult
|
||||
/******************************************************************/
|
||||
/* 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 des 2 registres */
|
||||
bx lr @ return
|
||||
/******************************************************************/
|
||||
/* Converting a register to a decimal */
|
||||
/******************************************************************/
|
||||
/* r0 contains value and r1 address area */
|
||||
conversion10:
|
||||
push {r1-r4,lr} @ save registers
|
||||
mov r3,r1
|
||||
mov r2,#10
|
||||
|
||||
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
|
||||
@ and move spaces in first on area
|
||||
mov r1,#' ' @ space
|
||||
2:
|
||||
strb r1,[r3,r2] @ store space in area
|
||||
subs r2,#1 @ @ previous position
|
||||
bge 2b @ loop if r2 >= zéro
|
||||
|
||||
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 /* leave function */
|
||||
/***************************************************/
|
||||
/* integer division unsigned */
|
||||
/***************************************************/
|
||||
division:
|
||||
/* r0 contains dividend */
|
||||
/* r1 contains divisor */
|
||||
/* r2 returns quotient */
|
||||
/* r3 returns remainder */
|
||||
push {r4, lr}
|
||||
mov r2, #0 @ init quotient
|
||||
mov r3, #0 @ init remainder
|
||||
mov r4, #32 @ init counter bits
|
||||
b 2f
|
||||
1: @ loop
|
||||
movs r0, r0, LSL #1 @ r0 <- r0 << 1 updating cpsr (sets C if 31st bit of r0 was 1)
|
||||
adc r3, r3, r3 @ r3 <- r3 + r3 + C. This is equivalent to r3 ? (r3 << 1) + C
|
||||
cmp r3, r1 @ compute r3 - r1 and update cpsr
|
||||
subhs r3, r3, r1 @ if r3 >= r1 (C=1) then r3 ? r3 - r1
|
||||
adc r2, r2, r2 @ r2 <- r2 + r2 + C. This is equivalent to r2 <- (r2 << 1) + C
|
||||
2:
|
||||
subs r4, r4, #1 @ r4 <- r4 - 1
|
||||
bpl 1b @ if r4 >= 0 (N=0) then loop
|
||||
pop {r4, lr}
|
||||
bx lr
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN {
|
||||
for (i= 2; i <= 8; i = i + 2) {
|
||||
print i
|
||||
}
|
||||
print "Ain't never too late!"
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
PROC Main()
|
||||
BYTE i
|
||||
|
||||
FOR i=0 TO 70 STEP 7
|
||||
DO
|
||||
PrintF("%B ",i)
|
||||
OD
|
||||
RETURN
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
with Loopers;
|
||||
use Loopers;
|
||||
|
||||
|
||||
procedure For_Main is
|
||||
begin
|
||||
Looper_1;
|
||||
Looper_2;
|
||||
Looper_3;
|
||||
end For_Main;
|
||||
|
||||
|
||||
package Loopers is
|
||||
procedure Looper_1;
|
||||
procedure Looper_2;
|
||||
procedure Looper_3;
|
||||
end Loopers;
|
||||
|
||||
with Ada.Text_IO, Ada.Integer_Text_IO;
|
||||
use Ada.Text_IO, Ada.Integer_Text_IO;
|
||||
|
||||
package body Loopers is
|
||||
procedure Looper_1 is
|
||||
Values : array(1..5) of Integer := (2,4,6,8,10);
|
||||
begin
|
||||
for I in Values'Range loop
|
||||
Put(Values(I),0);
|
||||
if I = Values'Last then
|
||||
Put_Line(".");
|
||||
else
|
||||
Put(",");
|
||||
end if;
|
||||
end loop;
|
||||
end Looper_1;
|
||||
|
||||
procedure Looper_2 is
|
||||
E : Integer := 5;
|
||||
begin
|
||||
for I in 1..E loop
|
||||
Put(I*2,0);
|
||||
if I = E then
|
||||
Put_Line(".");
|
||||
else
|
||||
Put(",");
|
||||
end if;
|
||||
end loop;
|
||||
end Looper_2;
|
||||
|
||||
procedure Looper_3 is
|
||||
Values : array(1..10) of Integer := (1,2,3,4,5,6,7,8,9,10);
|
||||
Indices : array(1..5) of Integer := (2,4,6,8,10);
|
||||
begin
|
||||
for I in Indices'Range loop
|
||||
Put(Values(Indices(I)),0);
|
||||
if I = Indices'Last then
|
||||
Put_Line(".");
|
||||
else
|
||||
Put(",");
|
||||
end if;
|
||||
end loop;
|
||||
end Looper_3;
|
||||
|
||||
end Loopers;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for i from 2 to 8 by 2 do
|
||||
print( i )
|
||||
od
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
integer i;
|
||||
|
||||
i = 0;
|
||||
while (i < 10) {
|
||||
o_winteger(2, i);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
o_newline();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
repeat with i from 2 to 10 by 2
|
||||
log i
|
||||
end repeat
|
||||
|
|
@ -0,0 +1 @@
|
|||
FOR I = 2 TO 8 STEP 2 : PRINT I; ", "; : NEXT I : PRINT "WHO DO WE APPRECIATE?"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
loop 0..10 .step:2 'i [
|
||||
print i
|
||||
]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
SetBatchLines, -1
|
||||
iterations := 5
|
||||
step := 10
|
||||
iterations *= step
|
||||
Loop, % iterations
|
||||
{
|
||||
If Mod(A_Index, step)
|
||||
Continue
|
||||
MsgBox, % A_Index
|
||||
}
|
||||
ExitApp
|
||||
|
|
@ -0,0 +1 @@
|
|||
For each i from 0 to 100 by 7 do [Print: “i” ++ " is a multiple of 7!\n";];
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
For(I,0,10)
|
||||
Disp I▶Dec,i
|
||||
I++
|
||||
End
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for i = 2 to 8 step 2
|
||||
print i; ", ";
|
||||
next i
|
||||
print "who do we appreciate?"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for i = 1 to 21 step 2
|
||||
print i; " ";
|
||||
next i
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
FOR n = 2 TO 8 STEP 1.5
|
||||
PRINT n
|
||||
NEXT
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
FOR i = 1 TO 10 STEP 2
|
||||
PRINT i
|
||||
NEXT
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
@echo off
|
||||
for /l %%A in (1,2,10) do (
|
||||
echo %%A
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for (i = 2; i <= 10; i += 2) {
|
||||
i
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
1 >:.55+,v
|
||||
@_^#`9:+2<
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
for (int i = 1; i < 10; i += 2)
|
||||
std::cout << i << std::endl;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
foreach x (`jot - 2 8 2`)
|
||||
echo $x
|
||||
end
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
for (int i = 2; i <= 8; i+= 2) {
|
||||
Console.Write("{0}, ", i);
|
||||
}
|
||||
|
||||
Console.WriteLine("who do we appreciate?");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
int i;
|
||||
for(i = 1; i < 10; i += 2)
|
||||
printf("%d\n", i);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
% This prints all odd digits
|
||||
|
||||
start_up = proc ()
|
||||
po: stream := stream$primary_output()
|
||||
|
||||
for i: int in int$from_to_by(1, 10, 2) do
|
||||
stream$putl(po, int$unparse(i))
|
||||
end
|
||||
end start_up
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Display-Odd-Nums.
|
||||
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 I PIC 99.
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
PERFORM VARYING I FROM 1 BY 2 UNTIL 10 < I
|
||||
DISPLAY I
|
||||
END-PERFORM
|
||||
|
||||
GOBACK
|
||||
.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
shared void run() {
|
||||
|
||||
for(i in (2..8).by(2)) {
|
||||
process.write("``i`` ");
|
||||
}
|
||||
print("who do we appreciate?");
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// Can be set on commandline via --N=x
|
||||
config const N = 3;
|
||||
|
||||
for i in 1 .. 10 by N {
|
||||
writeln(i);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 for i = 1 to 21 step 2
|
||||
20 print i;
|
||||
30 next i
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
SinOsc s => dac;
|
||||
|
||||
for (0 => int i; i < 2000; 5 +=> i )
|
||||
{
|
||||
i => s.freq;
|
||||
100::ms => now;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for (0 => int i; i < 2000; 5 +=> i )
|
||||
{
|
||||
<<< i >>>;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(loop [i 0]
|
||||
(println i)
|
||||
(when (< i 10)
|
||||
(recur (+ 2 i))))
|
||||
|
||||
(doseq [i (range 0 12 2)]
|
||||
(println i))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
<cfloop from="0" to="99" step="3" index="i">
|
||||
<Cfoutput>#i#</Cfoutput>
|
||||
</cfloop>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 FOR I = 1 TO 10 STEP 2
|
||||
20 PRINT I
|
||||
30 NEXT
|
||||
|
|
@ -0,0 +1 @@
|
|||
(format t "~{~S, ~}who do we appreciate?~%" (loop for i from 2 to 8 by 2 collect i))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(do ((n 0 (incf n (+ (random 3) 2)))) ; Initialize to 0 and set random step-value 2, 3 or 4
|
||||
((> n 20)) ; Break condition
|
||||
(print n)) ; On every loop print value
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import std.stdio, std.range;
|
||||
|
||||
void main() {
|
||||
// Print odd numbers up to 9.
|
||||
for (int i = 1; i < 10; i += 2)
|
||||
writeln(i);
|
||||
|
||||
// Alternative way.
|
||||
foreach (i; iota(1, 10, 2))
|
||||
writeln(i);
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
var i : Integer;
|
||||
|
||||
for i := 2 to 8 step 2 do
|
||||
PrintLn(i);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
# first value: 1
|
||||
# max value: 9
|
||||
# step: 2
|
||||
for( i = 1 : 2 : 9 ) io.writeln( i )
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
main() {
|
||||
for (int i = 1; i <= 21; i += 2) print(i);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
program LoopWithStep;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
i:=2;
|
||||
while i <= 8 do begin
|
||||
WriteLn(i);
|
||||
Inc(i, 2);
|
||||
end;
|
||||
end.
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for(i = 2, i <= 8,i += 2){
|
||||
show ", " + i
|
||||
}
|
||||
showln "who do we appreciate?"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
//Prints odd numbers from 1 to 10
|
||||
for i in 1^2..10 {
|
||||
print(i)
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
var i := 2
|
||||
while (i <= 8) {
|
||||
print(`$i, `)
|
||||
i += 2
|
||||
}
|
||||
println("who do we appreciate?")
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
def stepRange(low, high, step) {
|
||||
def range {
|
||||
to iterate(f) {
|
||||
var i := low
|
||||
while (i <= high) {
|
||||
f(null, i)
|
||||
i += step
|
||||
}
|
||||
}
|
||||
}
|
||||
return range
|
||||
}
|
||||
|
||||
for i in stepRange(2, 9, 2) {
|
||||
print(`$i, `)
|
||||
}
|
||||
println("who do we appreciate?")
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for i ? (i %% 2 <=> 0) in 2..8 {
|
||||
print(`$i, `)
|
||||
}
|
||||
println("who do we appreciate?")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
FOR N=2 TO 8 STEP 1.5 DO
|
||||
PRINT(N)
|
||||
END FOR
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# Prints even numbers from 0 to 100
|
||||
for i = 0 step 2 to 100
|
||||
print i
|
||||
.
|
||||
# Decimal step value
|
||||
for i = 0 step 1.23 to 100
|
||||
print i
|
||||
.
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(for ((i (in-range 0 15 2))) (write i))
|
||||
0 2 4 6 8 10 12 14
|
||||
|
||||
(for ((q (in-range 0 15 14/8))) (write q))
|
||||
0 7/4 7/2 21/4 7 35/4 21/2 49/4 14
|
||||
|
||||
(for ((x (in-range 0 15 PI))) (write x))
|
||||
0 3.141592653589793 6.283185307179586 9.42477796076938 12.566370614359172
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
open monad io
|
||||
|
||||
for m s n | n > m = do return ()
|
||||
| else = do
|
||||
putStrLn (show n)
|
||||
for m s (n+s)
|
||||
|
||||
_ = for 10 2 0 ::: IO
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
public program()
|
||||
{
|
||||
for(int i := 2, i <= 8, i += 2 )
|
||||
{
|
||||
console.writeLine:i
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
defmodule Loops do
|
||||
def for_step(n, step) do
|
||||
IO.inspect Enum.take_every(1..n, step)
|
||||
end
|
||||
end
|
||||
|
||||
Loops.for_step(20, 3)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
iex(1)> Stream.iterate(1, &(&1+2)) |> Enum.take(10)
|
||||
[1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
%% Implemented by Arjun Sunel
|
||||
%% for_loop/4 by Bengt Kleberg.
|
||||
-module(loop_step).
|
||||
-export([main/0, for_loop/1, for_loop/4]).
|
||||
|
||||
% This Erlang code for "For Loop" is equivalent to: " for (i=start; i<end ; i=i+2){ printf("* ");} " in C language.
|
||||
|
||||
main() ->
|
||||
for_loop(1).
|
||||
|
||||
for_loop( N ) ->
|
||||
for_loop( N, 4, 2, fun() -> io:fwrite("* ") end ).
|
||||
|
||||
for_loop( I, End, Step, Do ) when N < End ->
|
||||
Do(),
|
||||
for_loop( I+Step, End, Step, Do );
|
||||
for_loop( _I, _End, _Step, _Do ) -> ok.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for i = 1 to 10 by 2 do
|
||||
? i
|
||||
end for
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
print(1, something)
|
||||
puts(1, "\n")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for i in 2..2..8 do
|
||||
printf "%d, " i
|
||||
printfn "done"
|
||||
|
|
@ -0,0 +1 @@
|
|||
2[$9\>][$.", "2+]#"who do we appreciate!"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#APPTYPE CONSOLE
|
||||
|
||||
DIM n AS INTEGER
|
||||
FOR n = 2 TO 8 STEP 2
|
||||
PRINT n;
|
||||
IF n < 8 THEN PRINT " ";
|
||||
NEXT
|
||||
PRINT ", who will we obliterate?"
|
||||
PAUSE
|
||||
|
|
@ -0,0 +1 @@
|
|||
FOR I = 1,3,10; TYPE I, !
|
||||
|
|
@ -0,0 +1 @@
|
|||
1 10 2 <range> [ . ] each
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
Int step := 5
|
||||
for (Int i := 0; i < 100; i += step)
|
||||
{
|
||||
echo (i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
for i = 1 to 100 by 13 do !i;!' '; od
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
: test
|
||||
9 2 do
|
||||
i .
|
||||
2 +loop
|
||||
." who do we appreciate?" cr ;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
do i = 1,10,2
|
||||
print *, i
|
||||
end do
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
PROGRAM STEPFOR
|
||||
INTEGER I
|
||||
|
||||
C This will print all even numbers from -10 to +10, inclusive.
|
||||
DO 10 I = -10, 10, 2
|
||||
WRITE (*,*) I
|
||||
10 CONTINUE
|
||||
|
||||
STOP
|
||||
END
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
For i As Integer = 1 To 21 Step 2
|
||||
Print i; " ";
|
||||
Next
|
||||
Print
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
for a = 1 to 100 step 5
|
||||
println[a]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
for a = 1 km to 3 km step 1 meter
|
||||
println[a]
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
dim as Str15 s(11)
|
||||
dim as long i
|
||||
|
||||
s(0) = "Somewhere"
|
||||
s(2) = " over"
|
||||
s(4) = " the"
|
||||
s(6) = " rainbow" + chr$(13)
|
||||
s(8) = "Bluebirds"
|
||||
s(10) = " fly."
|
||||
|
||||
for i = 0 to 10 step 2
|
||||
print s(i);
|
||||
next
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
for i in [1, 3 .. 11] do
|
||||
Print(i, "\n");
|
||||
od;
|
||||
|
||||
1
|
||||
3
|
||||
5
|
||||
7
|
||||
9
|
||||
11
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
for(i = 0; i < 10; i += 2)
|
||||
show_message(string(i))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 FOR I = 1 TO 21 STEP 2
|
||||
20 PRINT I;
|
||||
30 NEXT I
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Public Sub Main()
|
||||
Dim siCount As Short
|
||||
|
||||
For siCount = 1 To 50 Step 5
|
||||
Print "Gambas is great!"
|
||||
Next
|
||||
|
||||
End
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for i := 1; i < 10; i += 2 {
|
||||
fmt.Printf("%d\n", i)
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for(i in (2..9).step(2)) {
|
||||
print "${i} "
|
||||
}
|
||||
println "Who do we appreciate?"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(2..9).step(2).each {
|
||||
print "${it} "
|
||||
}
|
||||
println "Who do we appreciate?"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import Control.Monad (forM_)
|
||||
main = do forM_ [2,4..8] (\x -> putStr (show x ++ ", "))
|
||||
putStrLn "who do we appreciate?"
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
class Step {
|
||||
var end:Int;
|
||||
var step:Int;
|
||||
var index:Int;
|
||||
|
||||
public inline function new(start:Int, end:Int, step:Int) {
|
||||
this.index = start;
|
||||
this.end = end;
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
public inline function hasNext() return step > 0 ? end >= index : index >= end;
|
||||
public inline function next() return (index += step) - step;
|
||||
}
|
||||
|
||||
class Main {
|
||||
static function main() {
|
||||
for (i in new Step(2, 8, 2)) {
|
||||
Sys.print('$i ');
|
||||
}
|
||||
Sys.println('WHOM do we appreciate? GRAMMAR! GRAMMAR! GRAMMAR!');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for let i 0; i <= 50; let i (i + 5)
|
||||
println i
|
||||
endfor
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
DO i = 1, 6, 1.25 ! from 1 to 6 step 1.25
|
||||
WRITE() i
|
||||
ENDDO
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
U8 i;
|
||||
for (i = 1; i < 10; i += 2)
|
||||
Print("%d\n", i);
|
||||
|
|
@ -0,0 +1 @@
|
|||
(for [i (range 1 10 2)] (print i))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
100 FOR I=1 TO 10 STEP 2
|
||||
110 PRINT I
|
||||
120 NEXT
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
every 1 to 10 by 2 # the simplest case that satisfies the task, step by 2
|
||||
|
||||
every 1 to 10 # no to, step is by 1 by default
|
||||
every EXPR1 to EXPR2 by EXPR3 do EXPR4 # general case - EXPRn can be complete expressions including other generators such as to-by, every's do is optional
|
||||
steps := [2,3,5,7] # a list
|
||||
every i := 1 to 100 by !steps # . more complex, several passes with each step in the list steps, also we might want to know what value we are at
|
||||
every L[1 to 100 by 2] # as a list index
|
||||
every i := 1 to 100 by (k := !steps) # . need () otherwise := generates an error
|
||||
every 1 to 5 to 10 # simple case of combined to-by - 1,..,10, 2,..10, ..., 5,..,10
|
||||
every 1 to 15 by 2 to 5 # combined to-by
|
||||
every (1 to 15 by 2) to 5 # . made explicit
|
||||
|
||||
every writes( (TO_BY_EXPR) | "\n", " " ) # if you want to see how any of these work
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
for(i,2,8,2,
|
||||
write(i,", ")
|
||||
)
|
||||
write("who do we appreciate?")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
' who do we appreciate?' ,~ ": 2 * >: i.4
|
||||
2 4 6 8 who do we appreciate?
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
0 2 (p. i.) 5
|
||||
0 2 4 6 8
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
3 :0''
|
||||
r=.$0
|
||||
for_n. 2 * >: i.4 do.
|
||||
r=.r,n
|
||||
end.
|
||||
' who do we appreciate?' ,~ ":n
|
||||
)
|
||||
2 4 6 8 who do we appreciate?
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
i:8
|
||||
_8 _7 _6 _5 _4 _3 _2 _1 0 1 2 3 4 5 6 7 8
|
||||
i:8j8
|
||||
_8 _6 _4 _2 0 2 4 6 8
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue