task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#Chef
Chef
Asterisks Omelette.   This recipe prints a triangle of asterisks.   Ingredients. 5 eggs 1 onion 1 potato 42 ml water 10 ml olive oil 1 garlic   Method. Put eggs into the mixing bowl. Fold onion into the mixing bowl. Put eggs into the mixing bowl. Add garlic into the mixing bowl. Fold eggs into the mixing bowl. Chop oni...
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#Elixir
Elixir
defmodule Loops do def for_step(n, step) do IO.inspect Enum.take_every(1..n, step) end end   Loops.for_step(20, 3)
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lambdatalk
Lambdatalk
  {def loops_N_plus_one_half {lambda {:i :n} {if {> :i :n} then (end of loop with a dot) else {if {= :i 6} then {br}:i else :i}{if {= :i :n} then . else ,} {loops_N_plus_one_half {+ :i 1} :n}}}} -> loops_N_plus_one_half   {loops_N_plus_one_half 0 10} -> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10. (end of loop w...
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Liberty_BASIC
Liberty BASIC
dim ar(10,10) for i = 1 to 10 for j = 1 to 10 ar(i, j) = int(rnd(1) * 20) + 1 next next   flag=0 for x = 1 to 10 for y = 1 to 10 print ar(x,y) if ar(x,y) = 20 then flag=1 exit for end if next if flag then exit for next print "Completed row ";x;...
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Maple
Maple
  for p in [2, 3, 5, 7] do print(p); end do;  
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
s = (StringSplit@Import["ExampleData/USConstitution.txt"])[[1;;7]]; Do[ Print@i, {i, s} ]
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#GAP
GAP
IsLuhn := function(n) local c, d, i, j, r; d := "0123456789"; j := 1; r := 0; for c in Reversed(String(n)) do i := Position(d, c); if i = fail then continue; fi; i := j*(i - 1); r := r + QuoInt(i, 10) + RemInt(i, 10); j := 3 - j; od; return RemInt(r, 10) = 0; end;   List([49927398716, 49927398717,...
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#R
R
  # vectorized approach based on scalar code from primeSieve and mersenne in CRAN package `numbers` require(gmp) n <- 4423 # note that the sieve below assumes n > 9   # sieve the set of primes up to n p <- seq(1, n, by = 2) q <- length(p) p[1] <- 2 for (k in seq(3, sqrt(n), by = 2)) if (p[(k + 1)/2] != 0) p[seq...
http://rosettacode.org/wiki/LZW_compression
LZW compression
The Lempel-Ziv-Welch (LZW) algorithm provides loss-less data compression. You can read a complete description of it in the   Wikipedia article   on the subject.   It was patented, but it entered the public domain in 2004.
#zkl
zkl
fcn lzwCompress(uncompressed){ // text-->list of 12 bit ints dictionary:=(256).pump(Dictionary(),fcn(n){ return(n.toChar(),n) }); w,compressed:="",List(); foreach c in (uncompressed){ wc:=w+c; if(dictionary.holds(wc)) w=wc; else{ compressed.append(dictionary[w]); // 12 bits dictionary[...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#hexiscript
hexiscript
while true; println "SPAM"; endwhile
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#HicEst
HicEst
DO i = 1, 1E20 ! for i with 16 or more digits: i == i + 1 == loop infinite WRITE() "SPAM" ENDDO
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Go
Go
i := 1024 for i > 0 { fmt.Printf("%d\n", i) i /= 2 }
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Fortran
Fortran
DO i = 10, 0, -1 WRITE(*, *) i END DO
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#DWScript
DWScript
  var i := 0;   repeat Inc(i); PrintLn(i); until i mod 6 = 0;  
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#Clojure
Clojure
(doseq [i (range 5), j (range (inc i))] (print "*") (if (= i j) (println)))
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#Erlang
Erlang
%% 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(...
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lang5
Lang5
: , dup ", " 2 compress "" join ; 1 do dup 10 != if dup , . 1 + else . break then loop
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lasso
Lasso
local(out) = '' loop(10) => { #out->append(loop_count) loop_count == 10 ? loop_abort #out->append(', ') } #out
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Lingo
Lingo
-- create two-dimensional array with random numbers a = [] repeat with i = 1 to 20 a[i] = [] repeat with j = 1 to 20 a[i][j] = random(20) end repeat end repeat   -- iterate over rows and columns, print value, exit both loops if it's 20 repeat with i = 1 to 20 repeat with j = 1 to 20 v = a[i][j] put ...
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#MATLAB_.2F_Octave
MATLAB / Octave
list1 = [1,5,6,7,-7,-9]; for k = list1, % list1 must be a row vector (i.e. array of size 1xn) printf('%i\n',k) end;
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Maxima
Maxima
for n in [2, 3, 5, 7] do print(n);
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Go
Go
package main   import ( "fmt" "strings" )   const input = `49927398716 49927398717 1234567812345678 1234567812345670`   var t = [...]int{0, 2, 4, 6, 8, 1, 3, 5, 7, 9}   func luhn(s string) bool { odd := len(s) & 1 var sum int for i, c := range s { if c < '0' || c > '9' { return f...
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#Racket
Racket
  #lang racket (require math)   (define (mersenne-prime? p) (divides? (- (expt 2 p) 1) (S (- p 1))))   (define (S n) (if (= n 1) 4 (- (sqr (S (- n 1))) 2)))   (define (loop p) (when (mersenne-prime? p) (displayln p)) (loop (next-prime p)))   (loop 3)  
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#HolyC
HolyC
while(1) Print("SPAM\n");
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#Icon_and_Unicon
Icon and Unicon
procedure main() repeat write("SPAM") end
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Groovy
Groovy
int i = 1024 while (i > 0) { println i i /= 2 }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Haskell
Haskell
import Control.Monad (when)   main = loop 1024 where loop n = when (n > 0) (do print n loop (n `div` 2))
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Frink
Frink
  for i = 10 to 0 step -1 println[i]  
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#GAP
GAP
for i in [10, 9 .. 0] do Print(i, "\n"); od;
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Dyalect
Dyalect
var x = 0   do { x += 1 print(x) } while x % 6 != 0
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#E
E
var x := 0 __loop(fn { x += 1 println(x) x % 6 != 0 # this is the return value of the function })
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#CLU
CLU
start_up = proc () po: stream := stream$primary_output()   for i: int in int$from_to(1, 5) do for j: int in int$from_to(1, i) do stream$putc(po, '*') end stream$putl(po, "") end end start_up
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#ERRE
ERRE
  FOR N=2 TO 8 STEP 1.5 DO PRINT(N) END FOR  
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lhogho
Lhogho
for "i [1 10] [ type :i if :i < 10 [ type "|, | ] ] print
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Liberty_BASIC
Liberty BASIC
  for i =1 to 10 print i; if i =10 then exit for print ", "; next i end  
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Lisaac
Lisaac
Section Header   + name := TEST_LOOP_NESTED;   - external := `#include <time.h>`;   Section Public   - main <- ( + a : ARRAY2[INTEGER]; + i, j: INTEGER;   `srand(time(NULL))`; a := ARRAY2[INTEGER].create(0, 0) to (9, 9); 0.to 9 do { ii : INTEGER; 0.to 9 do { jj : INTEGER; a.put (`rand()`:INTEGER % 2...
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#LiveCode
LiveCode
repeat with i = 1 to 10 repeat with j = 1 to 10 put random(20) into aNums[i,j] end repeat end repeat   repeat with i = 1 to 10 repeat with j = 1 to 10 if aNums[i,j] = 20 then put true into exitLoop exit repeat end if end repeat if exitLoop then exit r...
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#MAXScript
MAXScript
  arr = for i in 1 to 50 collect ("Number: " + (random 10 99) as string) makeuniquearray arr sort arr   for i in arr do print i as string  
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Metafont
Metafont
for x = "mary", "had", "a", "little", "lamb": message x; endfor end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Groovy
Groovy
def checkLuhn(number) { int total (number as String).reverse().eachWithIndex { ch, index -> def digit = Integer.parseInt(ch) total += (index % 2 ==0) ? digit : [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][digit] } total % 10 == 0 }
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#Raku
Raku
multi is_mersenne_prime(2) { True } multi is_mersenne_prime(Int $p) { my $m_p = 2 ** $p - 1; my $s = 4; $s = $s.expmod(2, $m_p) - 2 for 3 .. $p; !$s }   .say for (2,3,5,7 … *).hyper(:8degree).grep( *.is-prime ).map: { next unless .&is_mersenne_prime; "M$_" };
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#IDL
IDL
while 1 do print,'SPAM'
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#Intercal
Intercal
NOTE THIS IS INTERCAL PLEASE ,1 <- #5 DO ,1 SUB #1 <- #54 DO ,1 SUB #2 <- #192 DO ,1 SUB #3 <- #136 PLEASE ,1 SUB #4 <- #208 DO ,1 SUB #5 <- #98 DO COME FROM (1) DO READ OUT ,1 (2) DO ,1 SUB #1 <- #134 (1) PLEASE ABSTAIN FROM (2)
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Haxe
Haxe
var i = 1024;   while (i > 0) { Sys.println(i); i >>= 1; }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#hexiscript
hexiscript
let i 1024 while i > 0 println i let i (i / 2) endwhile
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#GML
GML
for(i = 10; i >= 0; i -= 1) show_message(string(i))
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Go
Go
for i := 10; i >= 0; i-- { fmt.Println(i) }
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Ela
Ela
open monad io   loop n | n % 6 == 0 = do return () | else = do putStrLn (show n) loop (n+1)   _ = loop 10 ::: IO
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. Display-Triangle.   DATA DIVISION. WORKING-STORAGE SECTION. 01 Outer-Counter PIC 9. 01 Inner-Counter PIC 9.   PROCEDURE DIVISION. PERFORM VARYING Outer-Counter FROM 1 BY 1 UNTIL 5 < Outer-Counter   PERFORM VARYING...
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#Euphoria
Euphoria
  for i = 1 to 10 by 2 do ? i end for  
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lisaac
Lisaac
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; );
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#LiveCode
LiveCode
repeat with n = 1 to 10 put n after loopn if n is not 10 then put comma after loopn end repeat put loopn
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Logo
Logo
make "a mdarray [10 10]   for [j 1 10] [for [i 1 10] [mdsetitem list :i :j :a (1 + random 20)]]   to until.20 for [j 1 10] [ for [i 1 10] [ type mditem list :i :j :a type "| | if equal? 20 mditem list :i :j :a [stop] ] print "|| ] end until.20
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Lua
Lua
t = {} for i = 1, 20 do t[i] = {} for j = 1, 20 do t[i][j] = math.random(20) end end function exitable() for i = 1, 20 do for j = 1, 20 do if t[i][j] == 20 then return i, j end end end end print(exitable())
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#min
min
(1 2 3) 'puts foreach
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#MiniScript
MiniScript
for i in collection print i end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Haskell
Haskell
import Data.Char (digitToInt) luhn = (0 ==) . (`mod` 10) . sum . map (uncurry (+) . (`divMod` 10)) . zipWith (*) (cycle [1,2]) . map digitToInt . reverse
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#REXX
REXX
/*REXX pgm uses the Lucas─Lehmer primality test for prime powers of 2 (Mersenne primes)*/ @.=0; @.2=1; @.3=1; @.5=1; @.7=1; @.11=1; @.13=1 /*a partial list of some low primes. */ !.=@.;  !.0=1; !.2=1; !.4=1; !.5=1; !.6=1; !.8=1 /*#'s with these last digs aren't prime*/ parse arg limit . ...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#Io
Io
loop("SPAM" println)
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#J
J
(-[smoutput bind 'SPAM')^:_(1)
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#HolyC
HolyC
U16 i = 1024; while (i > 0) { Print("%d\n", i); i /= 2; }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Icon_and_Unicon
Icon and Unicon
procedure main() local i i := 1024 while write(0 < (i := i / 2)) end
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Groovy
Groovy
for (i in (10..0)) { println i }
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Elixir
Elixir
defmodule Loops do def do_while(n) do n1 = n + 1 IO.puts n1 if rem(n1, 6) == 0, do: :ok, else: do_while(n1) end end   Loops.do_while(0)
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#ColdFusion
ColdFusion
<cfloop index = "i" from = "1" to = "5"> <cfloop index = "j" from = "1" to = "#i#"> * </cfloop> < br /> </cfloop>
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#F.23
F#
for i in 2..2..8 do printf "%d, " i printfn "done"
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Logo
Logo
to comma.list :n repeat :n-1 [type repcount type "|, |] print :n end   comma.list 10
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#Lua
Lua
for i = 1, 10 do io.write(i) if i == 10 then break end io.write", " end
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { Dim A(10,10)<<Random(1, 20) For k=1 to 2 { For i=0 to 9 { For j=0 to 9 { Print A(i,j) if A(i,j)=20 then goto there } } ...
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Maple
Maple
(m,n) := LinearAlgebra:-Dimensions(M): for i from 1 to m do for j from 1 to n do print(M[i,j]); if M[i,j] = 20 then (i,j):=m,n; next; end if; end do; end do:
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#MOO
MOO
things = {"Apple", "Banana", "Coconut"};   for thing in (things) player:tell(thing); endfor
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Nanoquery
Nanoquery
for item in collection println item end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#HicEst
HicEst
CHARACTER numbers="49927398716 49927398717 1234567812345678 1234567812345670 "   DO nr = 1, 4 EDIT(Text=numbers, ITeM=nr, Parse=number) sum_odds = 0 sum_even = 0 DO i = LEN(number), 1, -2 sum_odds = sum_odds + ICHAR(number(i)) - 48 IF(i > 1) THEN even2 = 2 * (ICHAR(number(i-1)) - 48) ...
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#Ring
Ring
  see "Mersenne Primes :" + nl for p = 2 to 18 if lucasLehmer(p) see "M" + p + nl ok next   func lucasLehmer p i = 0 mp = 0 sn = 0 if p = 2 return true ok if (p and 1) = 0 return false ok mp = pow(2,p) - 1 sn = 4 for i = 3 to p sn = pow(sn,2) - 2 sn -= (mp * floor(sn...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#Java
Java
while (true) { System.out.println("SPAM"); }
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#JavaScript
JavaScript
for (;;) console.log("SPAM");
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Inform_7
Inform 7
let N be 1024; while N > 0: say "[N][line break]"; let N be N / 2;
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#IWBASIC
IWBASIC
  DEF X:INT   X=1024   OPENCONSOLE   WHILE X>0   PRINT X X=X/2   ENDWHILE 'Output starts with 1024 and ends with 1.   'Putting the following in the loop will produce output starting with 512 and ending with 0: 'X=X/2 'PRINT X   'When compiled as a console only program, a press any key to continue message is au...
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Harbour
Harbour
FOR i := 10 TO 0 STEP -1 ? i NEXT
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Haskell
Haskell
import Control.Monad   main :: IO () main = forM_ [10,9 .. 0] print
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Emacs_Lisp
Emacs Lisp
(let ((val 0)) (while (progn (setq val (1+ val)) (message "%d" val) (/= 0 (mod val 6)))))
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#Common_Lisp
Common Lisp
(loop for i from 1 upto 5 do (loop for j from 1 upto i do (write-char #\*)) (terpri))
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#Factor
Factor
1 10 2 <range> [ . ] each
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { \\ old type loop For i=1 to 10 Print i; If i=10 Then Exit For Print ", "; Next i Print \\ fast type loop. Continue exit block, without breaking loop. For i=1 to 10 { Print i; If i=10 Then Conti...
http://rosettacode.org/wiki/Loops/N_plus_one_half
Loops/N plus one half
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 th...
#M4
M4
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',`, ')')
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Do[ Print[m[[i, j]]]; If[m[[i, j]] === 20, Return[]], {i, 1, Dimensions[m][[1]]}, {j, 1, Dimensions[m][[2]]}]
http://rosettacode.org/wiki/Loops/Nested
Loops/Nested
Show a nested loop which searches a two-dimensional array filled with random numbers uniformly distributed over [ 1 , … , 20 ] {\displaystyle [1,\ldots ,20]} . The loops iterate rows and columns of the array printing the elements until the value 20 {\displaystyle 20} is met. Specifically, this task als...
#MATLAB_.2F_Octave
MATLAB / Octave
a = ceil(rand(100,100)*20); [ix,iy]=find(a==20,1)
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#Nemerle
Nemerle
def things = ["Apple", "Banana", "Coconut"];   foreach (thing in things) WriteLine(thing.ToLower()); foreach (i in [5, 10 .. 100]) Write($"$i\t");
http://rosettacode.org/wiki/Loops/Foreach
Loops/Foreach
Loop through and print each element in a collection in order. Use your language's "for each" loop if it has one, otherwise iterate through the collection in order with some other loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols nobinary   say say 'Loops/Foreach'   days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] daysl = Arrays.asList(days) daysi = daysl.iterator   loop while daysi.hasNext say daysi.next end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Icon_and_Unicon
Icon and Unicon
procedure main(aL) every write(i := !aL ," - ", ((\isluhn10(i),"valid")|"invalid") \ 1) end   procedure isluhn10(i) #: isluhn10(i) returns i (if i passes luhn10) or fails local sum   sum :=0 reverse(integer(i)) ? while not pos(0) do { sum +:= move(1) sum +:= map(move(1),"0123456789","0246813579") }...
http://rosettacode.org/wiki/Lucas-Lehmer_test
Lucas-Lehmer test
Lucas-Lehmer Test: for p {\displaystyle p} an odd prime, the Mersenne number 2 p − 1 {\displaystyle 2^{p}-1} is prime if and only if 2 p − 1 {\displaystyle 2^{p}-1} divides S ( p − 1 ) {\displaystyle S(p-1)} where S ( n + 1 ) = ( S ( n ) ) 2 − 2 {\displaystyle S(n+1)=(...
#RPL
RPL
  %%HP: T(3)A(R)F(.);  ; ASCII transfer header \<< DUP LN DUP \pi * 4 SWAP / 1 + UNROT / * IP 2 { 2 } ROT 2 SWAP  ; input n; n := Int(n/ln(n)*(1 + 4/(pi*ln(n)))), p:=2; (n ~ number of primes less then n, pi used here only as a convenience), 2 is assume...
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#Joy
Joy
DEFINE loop == [true []] dip while.   ["SPAM\n" putchars] loop.
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite 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 l...
#jq
jq
recurse("SPAM")
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#J
J
,. <.@-:^:*^:a: 1024
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Java
Java
int i = 1024; while(i > 0){ System.out.println(i); i >>= 1; //also acceptable: i /= 2; }
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#Haxe
Haxe
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 (in...
http://rosettacode.org/wiki/Loops/Downward_for
Loops/Downward for
Task Write a   for   loop which writes a countdown from   10   to   0. 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...
#hexiscript
hexiscript
for let i 10; i >= 0; i-- println i endfor
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Erlang
Erlang
  do() -> do(0).   do(0) -> io:fwrite( "0 " ), do( 1 ); do(N) when N rem 6 =:= 0 -> io:format("~w~n", [N]); do(N) -> io:fwrite( "~p ", [N] ), do(N+1).  
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#Coq
Coq
Section FOR. Variable T : Type. Variable body : nat -> T -> T. Variable start : nat.   Fixpoint for_loop n : T -> T := match n with | O => fun s => s | S n' => fun s => for_loop n' (body (start + n') s) end.   End FOR.   Eval vm_compute in for_loop _ (fun i => cons (for_loop ...
http://rosettacode.org/wiki/Loops/For_with_a_specified_step
Loops/For with a specified step
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 b...
#FALSE
FALSE
2[$9\>][$.", "2+]#"who do we appreciate!"