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 @@
<:400:~}:_:%<:a:~$=<:2:=/^:_:

View file

@ -0,0 +1 @@
Start an integer value at 1024. Loop while it is greater than 0. Print the value (with a newline) and divide it by two each time through the loop.

View file

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

View file

@ -0,0 +1,17 @@
LoopsWhile: PHA ;push accumulator onto stack
LDA #$00 ;the 6502 is an 8-bit processor
STA Ilow ;and so 1024 ($0400) must be stored in two memory locations
LDA #$04
STA Ihigh
WhileLoop: LDA Ilow
BNE NotZero
LDA Ihigh
BEQ EndLoop
NotZero: JSR PrintI ;routine not implemented
LSR Ihigh ;shift right
ROR Ilow ;rotate right
JMP WhileLoop
EndLoop: PLA ;restore accumulator from stack
RTS ;return from subroutine

View file

@ -0,0 +1,5 @@
INT i := 1024;
WHILE i > 0 DO
print(i);
i := i OVER 2
OD

View file

@ -0,0 +1,7 @@
BEGIN {
v = 1024
while(v > 0) {
print v
v = int(v/2)
}
}

View file

@ -0,0 +1,5 @@
var i:int = 1024;
while (i > 0) {
trace(i);
i /= 2;
}

View file

@ -0,0 +1,8 @@
declare
I : Integer := 1024;
begin
while I > 0 loop
Put_Line(Integer'Image(I));
I := I / 2;
end loop;
end;

View file

@ -0,0 +1,6 @@
// print 1024 512 etc
def i := 1024;
while: { i > 0 } do: {
system.print(" "+i);
i := i/2;
}

View file

@ -0,0 +1,7 @@
PROC main()
DEF i = 1024
WHILE i > 0
WriteF('\d\n', i)
i := i / 2
ENDWHILE
ENDPROC

View file

@ -0,0 +1,5 @@
set i to 1024
repeat while i > 0
log i
set i to i / 2
end repeat

View file

@ -0,0 +1,2 @@
10 I% = 1024
20 IF I% > 0 THEN PRINT I%:I% = I% / 2: GOTO 20

View file

@ -0,0 +1,7 @@
i = 1024
While (i > 0)
{
output = %output%`n%i%
i := Floor(i / 2)
}
MsgBox % output

View file

@ -0,0 +1,5 @@
i = 1024
while i > 0
print i
i = i / 2
wend

View file

@ -0,0 +1,5 @@
i% = 1024
WHILE i%
PRINT i%
i% DIV= 2
ENDWHILE

View file

@ -0,0 +1,2 @@
84*:*> :v
^/2.:_@

View file

@ -0,0 +1,5 @@
i = 1024
while { i > 0 } {
p i
i = (i / 2).to_i
}

View file

@ -0,0 +1,5 @@
int i = 1024;
while(i > 0) {
std::cout << i << std::endl;
i /= 2;
}

View file

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

View file

@ -0,0 +1,2 @@
for (init; cond; update)
statement;

View file

@ -0,0 +1,8 @@
{
init;
while (cond)
{
statement;
update;
}
}

View file

@ -0,0 +1,5 @@
int i = 1024;
while(i > 0) {
printf("%d\n", i);
i /= 2;
}

View file

@ -0,0 +1,4 @@
int i;
for(i = 1024;i > 0; i/=2){
printf("%d\n", i);
}

View file

@ -0,0 +1,5 @@
(def i (ref 1024))
(while (> @i 0)
(println @i)
(dosync (ref-set i (quot @i 2))))

View file

@ -0,0 +1,8 @@
(loop [i 1024]
(when (pos? i)
(println i)
(recur (quot i 2))))
(doseq [i (take-while pos? (iterate #(quot % 2) 1024))]
(println i))

View file

@ -0,0 +1,5 @@
<cfset i = 1024 />
<cfloop condition="i GT 0">
#i#< br />
<cfset i /= 2 />
</cfloop>

View file

@ -0,0 +1,7 @@
<cfscript>
i = 1024;
while( i > 0 )
{
writeOutput( i + "< br/ >" );
}
</cfscript>

View file

@ -0,0 +1,4 @@
(setq i 1024)
(loop while (> i 0) do
(print i)
(setq i (floor i 2)))

View file

@ -0,0 +1,5 @@
i = 1024;
while( i > 0 ) {
cout ` $i\n`;
i = i/2;
}

View file

@ -0,0 +1,10 @@
import std.stdio;
void main() {
int i = 1024;
while (i > 0) {
writeln(i);
i >>= 1;
}
}

View file

@ -0,0 +1,6 @@
var i := 1024;
while i > 0 do begin
PrintLn(i);
i := i div 2;
end;

View file

@ -0,0 +1,2 @@
i = 1024;
while( i > 0 ) i = i / 2;

View file

@ -0,0 +1 @@
1024[p2/d0<p]dspx

View file

@ -0,0 +1,11 @@
var
i : Integer;
begin
i := 1024;
while i > 0 do
begin
Writeln(i);
i := i div 2;
end;
end;

View file

@ -0,0 +1,5 @@
var i := 1024
while (i > 0) {
println(i)
i //= 2
}

View file

@ -0,0 +1,5 @@
x int = 1024;
while ( x > 0 )
SysLib.writeStdout( x );
x = MathLib.floor( x / 2 );
end

View file

@ -0,0 +1,7 @@
integer i
i = 1024
while i > 0 do
printf(1, "%g\n", {i})
i = floor(i/2) --Euphoria does NOT use integer division. 1/2 = 0.5
end while

View file

@ -0,0 +1,2 @@
1024[$0>][$."
"2/]#%

View file

@ -0,0 +1 @@
1024 [ dup 0 > ] [ dup . 2 /i ] while drop

View file

@ -0,0 +1,12 @@
class Main
{
public static Void main ()
{
Int i := 1024
while (i > 0)
{
echo (i)
i /= 2
}
}
}

View file

@ -0,0 +1,5 @@
: halving ( n -- )
begin dup 0 >
while cr dup . 2/
repeat drop ;
1024 halving

View file

@ -0,0 +1,5 @@
INTEGER :: i = 1024
DO WHILE (i > 0)
WRITE(*,*) i
i = i / 2
END DO

View file

@ -0,0 +1,33 @@
PROGRAM LOOPWHILE
INTEGER I
C FORTRAN 77 does not have a while loop, so we use GOTO statements
C with conditions instead. This is one of two easy ways to do it.
I = 1024
10 CONTINUE
C Check condition.
IF (I .GT. 0) THEN
C Handle I.
WRITE (*,*) I
I = I / 2
C Jump back to before the IF block.
GOTO 10
ENDIF
C This is an alternative while loop with labels on both ends. This
C will use the condition as a break rather than create an entire
C IF block. Which you use is up to you, but be aware that you must
C use this one if you plan on allowing for breaks.
I = 1024
20 CONTINUE
C If condition is false, break.
IF (I .LE. 0) GOTO 30
C Handle I.
WRITE (*,*) I
I = I / 2
C Jump back to the "loop" beginning.
GOTO 20
30 CONTINUE
STOP
END

View file

@ -0,0 +1,5 @@
i=1024
while i>0
{
i = i/1
}

View file

@ -0,0 +1,6 @@
i = 1024
while(i > 0)
{
show_message(string(i))
i /= 2
}

View file

@ -0,0 +1,5 @@
i := 1024
for i > 0 {
fmt.Printf("%d\n", i)
i /= 2
}

View file

@ -0,0 +1,5 @@
int i = 1024
while (i > 0) {
println i
i /= 2
}

View file

@ -0,0 +1,5 @@
import Control.Monad (when)
main = loop 1024
where loop n = when (n > 0)
(do print n
loop (n `div` 2))

View file

@ -0,0 +1,5 @@
import Control.Monad (when)
whileM :: (Monad m) => m Bool -> m a -> m ()
whileM cond body = do c <- cond
when c (body >> whileM cond body)

View file

@ -0,0 +1,9 @@
import Data.IORef
main :: IO ()
main = do r <- newIORef 1024
whileM (do n <- readIORef r
return (n > 0))
(do n <- readIORef r
print n
modifyIORef r (`div` 2))

View file

@ -0,0 +1,5 @@
procedure main()
local i
i := 1024
while write(0 < (i := i / 2))
end

View file

@ -0,0 +1,4 @@
let N be 1024;
while N > 0:
say "[N][line break]";
let N be N / 2;

View file

@ -0,0 +1 @@
,. <.@-:^:*^:a: 1024

View file

@ -0,0 +1,7 @@
monad define 1024
while. 0 < y do.
smoutput y
y =. <. -: y
end.
i.0 0
)

View file

@ -0,0 +1,5 @@
int i = 1024;
while(i > 0){
System.out.println(i);
i >>= 1; //also acceptable: i /= 2;
}

View file

@ -0,0 +1,3 @@
for(int i = 1024; i > 0;i /= 2 /*or i>>= 1*/){
System.out.println(i);
}

View file

@ -0,0 +1,5 @@
var n = 1024;
while (n>0) {
print(n);
n/=2;
}

View file

@ -0,0 +1,3 @@
DEFINE putln == put '\n putch.
1024 [] [dup putln 2 /] while.

View file

@ -0,0 +1,10 @@
HAI 1.3
I HAS A n ITZ 1024
IM IN YR loop UPPIN YR nop WILE n
VISIBLE n
n R QUOSHUNT OF n AN 2
IM OUTTA YR loop
KTHXBYE

View file

@ -0,0 +1,9 @@
: /i / int ; : 0= 0 == ;
: dip swap '_ set execute _ ; : dupd 'dup dip ;
: 2dip swap '_x set swap '_y set execute _y _x ;
: while
do dupd 'execute 2dip
rot 0= if break else dup 2dip then
loop ;
1024 "dup 0 >" "dup . 2 /i" while

View file

@ -0,0 +1,6 @@
i = 1024
while i > 0
print i
i = int( i / 2)
wend
end

View file

@ -0,0 +1,7 @@
+ i : INTEGER;
i := 1024;
{ i > 0 }.while_do {
i.println;
i := i / 2;
};

View file

@ -0,0 +1,2 @@
make "n 1024
while [:n > 0] [print :n make "n :n / 2]

View file

@ -0,0 +1,5 @@
n = 1024
while n>0 do
print(n)
n = math.floor(n/2)
end

View file

@ -0,0 +1,5 @@
i = 1024;
while (i > 0)
disp(i);
i = floor(i/2);
end

View file

@ -0,0 +1 @@
printf('%d\n', 2.^[log2(1024):-1:0]);

View file

@ -0,0 +1,6 @@
a = 1024
while a > 0 do
(
print a
a /= 2
)

View file

@ -0,0 +1,7 @@
alias while_loop {
var %n = 10
while (%n >= 0) {
echo -a Countdown: %n
dec %n
}
}

View file

@ -0,0 +1,5 @@
i = 1024;
while (i > 0)
player:tell(i);
i /= 2;
endwhile

View file

@ -0,0 +1,12 @@
NEXT=`expr $* / 2`
MAX=10
all: $(MAX)-n;
0-n:;
%-n: %-echo
@-make -f while.mk $(NEXT)-n MAX=$(MAX)
%-echo:
@echo $*

View file

@ -0,0 +1 @@
|make -f while.mk MAX=1024

View file

@ -0,0 +1,22 @@
> n := 1024: while n > 0 do print(n); n := iquo(n,2) end:
1024
512
256
128
64
32
16
8
4
2
1

View file

@ -0,0 +1,5 @@
i = 1024;
While[i > 0,
Print[i];
i = Floor[i/2];
]

View file

@ -0,0 +1,4 @@
block([n], n: 1024, while n > 0 do (print(n), n: quotient(n, 2)));
/* using a C-like loop: divide control variable by two instead of incrementing it */
for n: 1024 next quotient(n, 2) while n > 0 do print(n);

View file

@ -0,0 +1,5 @@
a := 1024;
forever: exitif not (a > 0);
show a;
a := a div 2;
endfor

View file

@ -0,0 +1,13 @@
MODULE DivBy2;
IMPORT InOut;
VAR
i: INTEGER;
BEGIN
i := 1024;
WHILE i > 0 DO
InOut.WriteInt(i, 4);
InOut.WriteLn;
i := i DIV 2
END
END DivBy2.

View file

@ -0,0 +1,9 @@
PROCEDURE DivBy2() =
VAR i: INTEGER := 1024;
BEGIN
WHILE i > 0 DO
IO.PutInt(i);
IO.Put("\n");
i := i DIV 2;
END;
END DivBy2;

View file

@ -0,0 +1,5 @@
$i = 1024;
while ($i > 0) {
echo "$i\n";
$i >>= 1;
}

View file

@ -0,0 +1,5 @@
my $n = 1024;
while ($n) {
print "$n\n";
$n = int $n / 2;
}

View file

@ -0,0 +1,5 @@
my $n = 1024;
until ($n <= 0) {
print "$n\n";
$n = int $n / 2;
}

View file

@ -0,0 +1,4 @@
(let N 1024
(while (gt0 N)
(println N)
(setq N (/ N 2)) ) )

View file

@ -0,0 +1,2 @@
while(0) :- !.
while(X) :- X>0,write(X), nl, X1 is X // 2, while(X1).

View file

@ -0,0 +1,4 @@
n = 1024
while n > 0:
print n
n //= 2

View file

@ -0,0 +1,6 @@
i <- 1024L
while(i > 0)
{
print(i)
i <- i %/% 2
}

View file

@ -0,0 +1,6 @@
/*REXX program to show a DO WHILE construct. */
j=1024
do while j>0
say j
j=j%2 /*in REXX, % is integer division. */
end

View file

@ -0,0 +1,6 @@
/*REXX program to show a DO WHILE construct. */
x=1024
do while x>0
say right(x,10) /*pretty up the output by aligning.*/
x=x%2 /*in REXX, % is integer division. */
end

View file

@ -0,0 +1,6 @@
/*REXX program to show a DO WHILE construct. */
x=1024
do while x>>0 /*this is an exact comparison. */
say right(x,10) /*pretty up the output by aligning.*/
x=x%2 /*in REXX, % is integer division. */
end

View file

@ -0,0 +1,5 @@
#lang racket
(let loop ([n 1024])
(when (positive? n)
(displayln n)
(loop (quotient n 2))))

View file

@ -0,0 +1,5 @@
i = 1024
while i > 0 do
puts i
i /= 2
end

View file

@ -0,0 +1,2 @@
i = 1024
puts i or i /= 2 while i > 0

View file

@ -0,0 +1,5 @@
i = 1024
until i <= 0 do
puts i
i /= 2
end

View file

@ -0,0 +1,9 @@
class MAIN is
main is
i ::= 1024;
loop while!(i > 0);
#OUT + i + "\n";
i := i / 2;
end;
end;
end;

View file

@ -0,0 +1,5 @@
var i = 1024
while (i > 0) {
println(i)
i /= 2
}

View file

@ -0,0 +1,4 @@
(do ((n 1024 (quotient n 2)))
((<= n 0))
(display n)
(newline))

View file

@ -0,0 +1,4 @@
number := 1024.
[ number > 0 ] whileTrue:
[ Transcript print: number; nl.
number := number // 2 ]

View file

@ -0,0 +1,4 @@
number := 1024.
[ number <= 0 ] whileFalse:
[ Transcript print: number; nl.
number := number // 2 ]

View file

@ -0,0 +1,5 @@
set i 1024
while {$i > 0} {
puts $i
set i [expr {$i / 2}]
}