This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
Demonstrate a for loop where the step value is greater than one.

View file

@ -0,0 +1,2 @@
---
note: Iteration

View file

@ -0,0 +1,6 @@
BEGIN {
for (l= 2; l <= 8; l = l + 2) {
print l
}
print "Ain't never to late!"
}

View file

@ -0,0 +1 @@
type Loop_Steps is (2, 4, 6, 8);

View file

@ -0,0 +1,5 @@
for Step in Loop_Steps loop
put(Step, 0);
put(", ");
end loop;
put("who do we appreciate?");

View file

@ -0,0 +1,7 @@
for Value in 3 .. 12 loop
if Value mod 3 = 0 then
put(Value, 0);
put(", ")
end if;
end loop;
put("what's a word that rhymes with ""twelve""?");

View file

@ -0,0 +1,11 @@
SetBatchLines, -1
iterations := 5
step := 10
iterations *= step
Loop, % iterations
{
If Mod(A_Index, step)
Continue
MsgBox, % A_Index
}
ExitApp

View file

@ -0,0 +1,4 @@
for i = 2 to 8 step 2
print i; ", ";
next i
print "who do we appreciate?"

View file

@ -0,0 +1,3 @@
FOR n = 2 TO 8 STEP 1.5
PRINT n
NEXT

View file

@ -0,0 +1,2 @@
for (int i = 1; i < 10; i += 2)
std::cout << i << std::endl;

View file

@ -0,0 +1,3 @@
int i;
for(i = 1; i < 10; i += 2)
printf("%d\n", i);

View file

@ -0,0 +1,7 @@
(loop [i 0]
(println i)
(when (< i 10)
(recur (+ 2 i))))
(doseq [i (range 0 12 2)]
(println i))

View file

@ -0,0 +1,3 @@
(loop for i from 2 to 8 by 2 do
(format t "~d, " i))
(format t "who do we appreciate?~%")

View file

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

View file

@ -0,0 +1,4 @@
var i : Integer;
for i := 2 to 8 step 2 do
PrintLn(i);

View file

@ -0,0 +1,4 @@
# first value: 1
# max value: 9
# step: 2
for( i = 1 : 2 : 9 ) io.writeln( i )

View file

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

View file

@ -0,0 +1,6 @@
var i := 2
while (i <= 8) {
print(`$i, `)
i += 2
}
println("who do we appreciate?")

View file

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

View file

@ -0,0 +1,4 @@
for i ? (i %% 2 <=> 0) in 2..8 {
print(`$i, `)
}
println("who do we appreciate?")

View file

@ -0,0 +1,6 @@
open console
for m s n | n > m = ()
| else = writen n $ for m s (n+s)
for 10 2 0

View file

@ -0,0 +1,3 @@
for i = 1 to 10 by 2 do
? i
end for

View file

@ -0,0 +1,2 @@
print(1, something)
puts(1, "\n")

View file

@ -0,0 +1 @@
2[$9\>][$.", "2+]#"who do we appreciate!"

View file

@ -0,0 +1 @@
1 10 2 <range> [ . ] each

View file

@ -0,0 +1,11 @@
class Main
{
public static Void main ()
{
Int step := 5
for (Int i := 0; i < 100; i += step)
{
echo (i)
}
}
}

View file

@ -0,0 +1,5 @@
: test
9 2 do
i .
2 +loop
." who do we appreciate?" cr ;

View file

@ -0,0 +1,3 @@
do i = 1,10,2
print *, i
end do

View file

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

View file

@ -0,0 +1,2 @@
for(i = 0; i < 10; i += 2)
show_message(string(i))

View file

@ -0,0 +1,3 @@
for i := 1; i < 10; i += 2 {
fmt.Printf("%d\n", i)
}

View file

@ -0,0 +1,4 @@
for(i in (2..9).step(2)) {
print "${i} "
}
println "Who do we appreciate?"

View file

@ -0,0 +1,4 @@
(2..9).step(2).each {
print "${it} "
}
println "Who do we appreciate?"

View file

@ -0,0 +1,3 @@
import Control.Monad (forM_)
main = do forM_ [2,4..8] (\x -> putStr (show x ++ ", "))
putStrLn "who do we appreciate?"

View file

@ -0,0 +1,3 @@
DO i = 1, 6, 1.25 ! from 1 to 6 step 1.25
WRITE() i
ENDDO

View file

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

View file

@ -0,0 +1,2 @@
' who do we appreciate?' ,~ ": 2 * >: i.4
2 4 6 8 who do we appreciate?

View file

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

View file

@ -0,0 +1,4 @@
for(int i = 2; i <= 8;i += 2){
System.out.print(i + ", ");
}
System.out.println("who do we appreciate?");

View file

@ -0,0 +1,7 @@
var output = '',
i;
for (i = 2; i <= 8; i += 2) {
output += i + ', ';
}
output += 'who do we appreciate?';
document.write(output);

View file

@ -0,0 +1,3 @@
: <range> over iota swap * rot + tuck swap <= select ; : tuck swap over ;
: >>say.(*) . ;
1 10 2 <range> >>say.

View file

@ -0,0 +1,5 @@
for i = 2 to 8 step 2
print i; ", ";
next i
print "who do we appreciate?"
end

View file

@ -0,0 +1,4 @@
1.to 9 by 2 do { i : INTEGER;
i.print;
'\n'.print;
};

View file

@ -0,0 +1 @@
for [i 2 8 2] [type :i type "|, |] print [who do we appreciate?]

View file

@ -0,0 +1,3 @@
for i=2,9,2 do
print(i)
end

View file

@ -0,0 +1,7 @@
define(`for',
`ifelse($#,0,``$0'',
`ifelse(eval($2<=$3),1,
`pushdef(`$1',$2)$5`'popdef(`$1')$0(`$1',eval($2+$4),$3,$4,`$5')')')')dnl
for(`x',`1',`5',`3',`x
')

View file

@ -0,0 +1,3 @@
for k = 0:10:100,
printf('%d\n',k)
end;

View file

@ -0,0 +1 @@
printf('%d\n',0:10:100);

View file

@ -0,0 +1,2 @@
FOR I=65:3:122 DO
.WRITE $CHAR(I)," "

View file

@ -0,0 +1,3 @@
Do[
Print@i,
{i, 1, 20, 4}]

View file

@ -0,0 +1,5 @@
for i: 1 step 2 thru 10 do print(i);
/* 1
3
5
7 */

View file

@ -0,0 +1,12 @@
MODULE ForBy;
IMPORT InOut;
VAR
i: INTEGER;
BEGIN
FOR i := 0 TO 100 BY 2 DO
InOut.WriteInt(i, 3);
InOut.WriteLn
END
END ForBy.

View file

@ -0,0 +1,3 @@
FOR i := 1 TO 100 BY 2 DO
IO.Put(Fmt.Int(i) & " ");
END;

View file

@ -0,0 +1,5 @@
<?php
foreach (range(2, 8, 2) as $i)
echo "$i, ";
echo "who do we appreciate?\n";
?>

View file

@ -0,0 +1,4 @@
for($i=2; $i <= 8; $i += 2) {
print "$i, ";
}
print "who do we appreciate?\n";

View file

@ -0,0 +1,2 @@
(for (N 1 (> 10 N) (+ N 2))
(printsp N) )

View file

@ -0,0 +1,3 @@
for i in xrange(2, 9, 2):
print "%d," % i,
print "who do we appreciate?"

View file

@ -0,0 +1,3 @@
for i in range(2, 9, 2):
print("%d, " % i, end="")
print("who do we appreciate?")

View file

@ -0,0 +1,4 @@
for(a in seq(2,8,2)) {
cat(a, ", ")
}
cat("who do we appreciate?\n")

View file

@ -0,0 +1,3 @@
do x=1 to 10 by 1.5
say x
end

View file

@ -0,0 +1,5 @@
#lang racket
(for ([i (in-range 2 9 2)])
(printf "~a, " i))
(printf "who do we appreciate?~n")

View file

@ -0,0 +1,2 @@
2.step(8,2) {|n| print "#{n}, "}
puts "who do we appreciate?"

View file

@ -0,0 +1,2 @@
(2..8).step(2) {|n| print "#{n}, "}
puts "who do we appreciate?"

View file

@ -0,0 +1,7 @@
i :INT;
loop
i := for!(1, 50, 2);
-- OR
-- i := 1.stepto!(50, 2);
#OUT + i + "\n";
end;

View file

@ -0,0 +1,3 @@
for (i <- 2 to 8 by 2) {
println(i)
}

View file

@ -0,0 +1 @@
(2 to 8 by 2) foreach println

View file

@ -0,0 +1,10 @@
(define (for-loop start end step func)
(let loop ((i start))
(cond ((< i end)
(func i)
(loop (+ i step))))))
(for-loop 2 9 2
(lambda (i)
(display i)
(newline)))

View file

@ -0,0 +1,4 @@
2 to: 8 by: 2 do: [ :i |
Transcript show: i; show ', '
].
Transcript showCr: 'enough with the cheering already!'

View file

@ -0,0 +1,4 @@
for {set i 2} {$i <= 8} {incr i 2} {
puts -nonewline "$i, "
}
puts "enough with the cheering already!"