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/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref symbols nobinary   numeric digits 40 -- make lots of space for big numbers numeric form scientific -- set output form for exponential notation   say 'Sample using objects of type "Rexx" (default):' fv = 1.5; say '1.5'.right(20) '==' normalize(fv).rig...
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Raku
Raku
sub is-long ($year) { Date.new("$year-12-28").week[1] == 53 }   # Testing say "Long years in the 20th century:\n", (1900..^2000).grep: &is-long; say "\nLong years in the 21st century:\n", (2000..^2100).grep: &is-long; say "\nLong years in the 22nd century:\n", (2100..^2200).grep: &is-long;
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#REXX
REXX
/*REXX program determines if a (calendar) year is a SHORT or LONG year (52 or 53 weeks).*/ parse arg LO HI . /*obtain optional args. */ if LO=='' | LO=="," | LO=='*' then LO= left( date('S'), 4) /*Not given? Use default.*/ if HI=='' | HI=="," then HI= LO ...
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Picat
Picat
go => println(findall(P, (member(P,primes(500)),long_prime(P)))), nl, println("Number of long primes up to limit are:"), foreach(Limit in [500,1_000,2_000,4_000,8_000,16_000,32_000,64_000]) printf(" <= %5d: %4d\n", Limit, count_all( (member(P,primes(Limit)), long_prime(P)) )) end, nl.   long_prime(P) =...
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously
Loop over multiple arrays simultaneously
Task Loop over multiple arrays   (or lists or tuples or whatever they're called in your language)   and display the   i th   element of each. Use your language's   "for each"   loop if it has one, otherwise iterate through the collection in order with some other loop. For this example, loop over the arrays: ...
#D
D
import std.stdio, std.range;   void main () { foreach (a, b, c; zip("abc", "ABC", [1, 2, 3])) writeln(a, b, c); }
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#ERRE
ERRE
  LOOP A=INT(RND(1)*20) PRINT(A) IF A=10 THEN EXIT LOOP END IF !EXIT FOR works the same inside FOR loops PRINT(INT(RND(1)*20)) END LOOP  
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Euphoria
Euphoria
integer i while 1 do i = rand(20) - 1 printf(1, "%g ", {i}) if i = 10 then exit end if printf(1, "%g ", {rand(20)-1}) end while
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Groovy
Groovy
def lcs(xstr, ystr) { if (xstr == "" || ystr == "") { return ""; }   def x = xstr[0]; def y = ystr[0];   def xs = xstr.size() > 1 ? xstr[1..-1] : ""; def ys = ystr.size() > 1 ? ystr[1..-1] : "";   if (x == y) { return (x + lcs(xs, ys)); }   def lcs1 = lcs(xstr, ys...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Crystal
Crystal
class String def lookandsay gsub(/(.)\1*/){ |s| s.size.to_s + s[0] } end end   ss = '1' 12.times { puts ss; ss = ss.to_s.lookandsay }
http://rosettacode.org/wiki/Longest_string_challenge
Longest string challenge
Background This "longest string challenge" is inspired by a problem that used to be given to students learning Icon. Students were expected to try to solve the problem in Icon and another language with which the student was already familiar. The basic problem is quite simple; the challenge and fun part came through th...
#Wren
Wren
import "io" for Stdin   // Return a.length - b.length if positive, 0 otherwise. var longer = Fn.new { |a, b| while (!a.isEmpty && !b.isEmpty) { a = a[1..-1] b = b[1..-1] } return a.count }   var longest = "" var lines = "" var line while ((line = Stdin.readLine()) != "") { if (longer.cal...
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#PicoLisp
PicoLisp
(de longinc (Lst) (let (D NIL R NIL) (for I Lst (cond ((< I (last D)) (for (Y . X) D (T (> X I) (set (nth D Y) I)) ) ) ((< I (car R)) (set R I) (when D (set (cdr R) (last D))) ) (T (when R (queue 'D (ca...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#J
J
_2}."1'lq<, >'8!:2>:i.2 5
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Java
Java
for(int i = 1;i <= 10; i++){ System.out.print(i); if(i % 5 == 0){ System.out.println(); continue; } System.out.print(", "); }
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Python
Python
s1 = "thisisatest" s2 = "testing123testing" len1, len2 = len(s1), len(s2) ir, jr = 0, -1 for i1 in range(len1): i2 = s2.find(s1[i1]) while i2 >= 0: j1, j2 = i1, i2 while j1 < len1 and j2 < len2 and s2[j2] == s1[j1]: if j1-i1 >= jr-ir: ir, jr = i1, j1 j1 +=...
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...
#Python
Python
>>> def luhn(n): r = [int(ch) for ch in str(n)][::-1] return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0   >>> for n in (49927398716, 49927398717, 1234567812345678, 1234567812345670): print(n, luhn(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...
#SQL_PL
SQL PL
  --#SET TERMINATOR @   SET SERVEROUTPUT ON@   BEGIN DECLARE I SMALLINT DEFAULT 1; WHILE (I = I) DO CALL DBMS_OUTPUT.PUT_LINE('SPAM'); END WHILE; END @  
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...
#Standard_ML
Standard ML
while true do 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...
#Stata
Stata
while 1 { display "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...
#Ring
Ring
  i = 1024 while i > 0 see i + nl i = floor(i / 2) 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...
#Ruby
Ruby
i = 1024 while i > 0 do puts 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...
#SSEM
SSEM
10001000000000100000000000000000 0. -17 to c 11001000000001100000000000000000 1. c to 19 11001000000000100000000000000000 2. -19 to c 01001000000000010000000000000000 3. Sub. 18 00010000000001100000000000000000 4. c to 8 01001000000000100000000000000000 5. -18 to c 11001000000001100000000000000000 6. c to...
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...
#Stata
Stata
forvalues n=10(-1)0 { display `n' }   forvalues n=10 9 to 0 { display `n' }   foreach n of numlist 10/0 { display `n' }
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...
#Pascal
Pascal
program countto6(output);   var i: integer;   begin i := 0; repeat i := i + 1; writeln(i) until i mod 6 = 0 end.
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...
#Perl
Perl
my $val = 0; do { $val++; print "$val\n"; } while ($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. ...
#Haskell
Haskell
import Control.Monad   main = do forM_ [1..5] $ \i -> do forM_ [1..i] $ \j -> do putChar '*' putChar '\n'
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols nobinary   say say 'Loops/For with a specified step'   loop i_ = -1.4 to 10.6 by 1.7 say i_.format(3, 1) || '\0' end i_ say
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...
#Never
Never
for (i = 0; i < 10; i += 3)
http://rosettacode.org/wiki/Long_multiplication
Long multiplication
Task Explicitly implement   long multiplication. This is one possible approach to arbitrary-precision integer algebra. For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: 18,446,744,073,709,551,61...
#CoffeeScript
CoffeeScript
  # This very limited BCD-based collection of functions # allows for long multiplication. It works for positive # numbers only. The assumed data structure is as follows: # BcdInteger.from_integer(4321) == [1, 2, 3, 4]   BcdInteger = from_string: (s) -> arr = [] for c in s arr.unshift parseInt(c) a...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Elixir
Elixir
  IO.puts "Begin String \n============" str = "string" str |> is_binary # true  
http://rosettacode.org/wiki/List_rooted_trees
List rooted trees
You came back from grocery shopping.   After putting away all the goods, you are left with a pile of plastic bags, which you want to save for later use, so you take one bag and stuff all the others into it, and throw it under the sink.   In doing so, you realize that there are various ways of nesting the bags, with all...
#Wren
Wren
import "/long" for ULong import "os" for Process   var treeList = [] var offset = List.filled(32, 0) offset[1] = 1   var append = Fn.new { |t| treeList.add(ULong.one | (t << 1)) }   var show = Fn.new { |t, len| while (len > 0) { len = len - 1 System.write(t.isOdd ? "(" : ")") t = t >> 1 ...
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Efene
Efene
@public run = fn () { io.format("0xff  : ~B~n", [0xff]) io.format("0xFF  : ~B~n", [0xFF]) io.format("0o777 : ~B~n", [0o777]) io.format("0b1011: ~B~n", [0b1011]) }  
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Eiffel
Eiffel
  123 -- decimal -1_2_3 -- decimal 0x7b -- hexadecimal 0c173 -- octal 0b111_1011 -- binary  
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Clipper
Clipper
Function Foo( a, b ) // a and b was defined as .F. (false) or .T. (true)  ? a .AND. b  ? a .OR. b  ? .NOT. a, .NOT. b Return Nil  
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Clojure
Clojure
  (defn logical [a b] (prn (str "a and b is " (and a b))) (prn (str "a or b is " (or a b))) (prn (str "not a is " (not a))))   (logical true false)  
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Nim
Nim
var x: float x = 2.3 x = 2.0 x = 0.3 x = 123_456_789.000_000_1 x = 2e10 x = 2.5e10 x = 2.523_123E10 x = 5.2e-10   var y = 2'f32 # Automatically a float32 var z = 2'f64 # Automatically a float64  
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Objeck
Objeck
  3 + .14159 3.14159 314.159E-2  
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#OCaml
OCaml
float-literal  ::= [-] (0…9) { 0…9∣ _ } [. { 0…9∣ _ }] [(e∣ E) [+∣ -] (0…9) { 0…9∣ _ }]
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Ring
Ring
  see "long years 2000-2099: " for year = 2000 to 2100 num1 = (year-1900)%7 num2 = floor((year-1904)/4) num3 = (num1+num2+5)%7 if num3 = 0 or (num1 = 6 and num3 = 1) see "" + year + " " ok next  
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Ruby
Ruby
  require 'date'   def long_year?(year = Date.today.year) Date.new(year, 12, 28).cweek == 53 end   (2020..2030).each{|year| puts "#{year} is long? #{ long_year?(year) }." }  
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Rust
Rust
extern crate time; // 0.2.16   use time::Date;   fn main() { (2000..=2099) .filter(|&year| is_long_year(year)) .for_each(|year| println!("{}", year)); }   fn is_long_year(year: i32) -> bool { Date::try_from_ymd(year, 12, 28).map_or(false, |date| date.week() == 53) }  
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#Prolog
Prolog
% See https://en.wikipedia.org/wiki/Full_reptend_prime long_prime(Prime):- is_prime(Prime), M is 10 mod Prime, M > 1, primitive_root(10, Prime).   % See https://en.wikipedia.org/wiki/Primitive_root_modulo_n#Finding_primitive_roots primitive_root(Base, Prime):- Phi is Prime - 1, primitive_root(Ph...
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously
Loop over multiple arrays simultaneously
Task Loop over multiple arrays   (or lists or tuples or whatever they're called in your language)   and display the   i th   element of each. Use your language's   "for each"   loop if it has one, otherwise iterate through the collection in order with some other loop. For this example, loop over the arrays: ...
#Delphi
Delphi
program LoopOverArrays;   {$APPTYPE CONSOLE}   uses SysUtils;   const ARRAY1: array [1..3] of string = ('a', 'b', 'c'); ARRAY2: array [1..3] of string = ('A', 'B', 'C'); ARRAY3: array [1..3] of Integer = (1, 2, 3); var i: Integer; begin for i := 1 to 3 do Writeln(Format('%s%s%d', [ARRAY1[i], ARRAY2[i], AR...
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#F.23
F#
  // Loops/Break. Nigel Galloway: February 21st., 2022 let n=System.Random() let rec fN g=printf "%d " g; if g <> 10 then fN(n.Next(20)) fN(n.Next(20))  
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Haskell
Haskell
longest xs ys = if length xs > length ys then xs else ys   lcs [] _ = [] lcs _ [] = [] lcs (x:xs) (y:ys) | x == y = x : lcs xs ys | otherwise = longest (lcs (x:xs) ys) (lcs xs (y:ys))
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#D
D
import std.stdio, std.algorithm, std.range;   enum say = (in string s) pure => s.group.map!q{ text(a[1],a[0]) }.join;   void main() { "1".recurrence!((t, n) => t[n - 1].say).take(8).writeln; }
http://rosettacode.org/wiki/Longest_string_challenge
Longest string challenge
Background This "longest string challenge" is inspired by a problem that used to be given to students learning Icon. Students were expected to try to solve the problem in Icon and another language with which the student was already familiar. The basic problem is quite simple; the challenge and fun part came through th...
#XQuery
XQuery
  let $seq as xs:string+ := ("a","bb","ccc","ddd","ee","f","ggg") for $l in max( for $s in $seq return string-length($s) ) return $seq[string-length(.) eq $l]  
http://rosettacode.org/wiki/Longest_string_challenge
Longest string challenge
Background This "longest string challenge" is inspired by a problem that used to be given to students learning Icon. Students were expected to try to solve the problem in Icon and another language with which the student was already familiar. The basic problem is quite simple; the challenge and fun part came through th...
#XSLT_2.0
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes" encoding="UTF-8" omit-xml-declaration="yes" /> <xsl:template match="/*"> <t><xsl:copy-of select="for $l in max( for $s in s return string-length($s)) return s[string-length(.) eq $l]" /></t> </xsl:template...
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#PowerShell
PowerShell
function Get-LongestSubsequence ( [int[]]$A ) { If ( $A.Count -lt 2 ) { return $A }   # Start with an "empty" pile # (We will only store the top value in each "pile".) $Pile = @( [int]::MaxValue ) $Last = 0   # Hashtable to hold the back pointers $BP = @{}   # For each number in ...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#JavaScript
JavaScript
var output = ""; for (var i = 1; i <= 10; i++) { output += i; if (i % 5 == 0) { print(output); output = ""; continue; } output += ", "; }
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Racket
Racket
#lang typed/racket (: lcs (String String -> String)) (define (lcs a b) (: all-substrings# (String -> (HashTable String Boolean))) (define (all-substrings# str) (define l (string-length str)) (for*/hash : (HashTable String Boolean) ((s (in-range 0 l)) (e (in-range (add1 s) (add1 l)))) (values (su...
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...
#Q
Q
sd:{s:0; while[x<>0; s+:x mod 10; x:floor x%10]; s} / Sum digits of x luhn:{ r:reverse string x; / Reversed credit card number o:("I"$) each r[2*til ceiling (count r) % 2]; / Odd-indexed numbers e:("I"$) each r[1+2*til floor (count r) % 2]; / Even-indexed numbers 0=(su...
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...
#Swift
Swift
while true { 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...
#SystemVerilog
SystemVerilog
program main; initial forever $display("SPAM"); endprogram  
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...
#Tailspin
Tailspin
  1 -> \( <> 'SPAM$#10;' -> !OUT::write 1 -> # \) -> !VOID  
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...
#Run_BASIC
Run BASIC
i = 1024 while i > 0 print i i = int(i / 2) wend 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...
#Rust
Rust
fn main() { let mut n: i32 = 1024; while n > 0 { println!("{}", n); n /= 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...
#Swift
Swift
for i in stride(from: 10, through: 0, by: -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...
#Tailspin
Tailspin
  10..0:-1 -> '$; ' -> !OUT::write  
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...
#Phix
Phix
integer x = 0 while 1 do x += 1 ?x if mod(x,6)=0 then exit end if end while
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...
#PHL
PHL
var i = 0; do { i = i::inc; printf("%i\n", i); } while (i%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. ...
#Haxe
Haxe
for (i in 1...6) { for(j in 0...i) { Sys.print('*'); } Sys.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...
#NewLISP
NewLISP
(for (i 0 10 2) (println i))
http://rosettacode.org/wiki/Long_multiplication
Long multiplication
Task Explicitly implement   long multiplication. This is one possible approach to arbitrary-precision integer algebra. For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: 18,446,744,073,709,551,61...
#Common_Lisp
Common Lisp
(defun number->digits (number) (do ((digits '())) ((zerop number) digits) (multiple-value-bind (quotient remainder) (floor number 10) (setf number quotient) (push remainder digits))))   (defun digits->number (digits) (reduce #'(lambda (n d) (+ (* 10 n) d)) digits :initial-value 0))   (defun long-mul...
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Emacs_Lisp
Emacs Lisp
"This is a string."
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Erlang
Erlang
  "This is a string". [$T,$h,$i,$s,$ ,$a,$ ,$s,$t,$r,$i,$n,$g,$,,$ ,$t,$o,$o].  
http://rosettacode.org/wiki/List_rooted_trees
List rooted trees
You came back from grocery shopping.   After putting away all the goods, you are left with a pile of plastic bags, which you want to save for later use, so you take one bag and stuff all the others into it, and throw it under the sink.   In doing so, you realize that there are various ways of nesting the bags, with all...
#zkl
zkl
fcn bags(n){ if(not n) return(T(T(0,"")));   [n-1 .. 1, -1].pump(List,bags).flatten() : bagchain(T(0,""), n-1, _).apply(fcn([(c,s)]){ T(c+1,String("(",s,")")) }) } fcn bagchain(x,n,bb,start=0){ if(not n) return(T(x));   out := List(); foreach i in ([start..bb.len()-1]){ c,s := bb[i]; if(c...
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Elena
Elena
  var n := 1234; // decimal number var x := 1234h; // hexadecimal number  
http://rosettacode.org/wiki/Literals/Integer
Literals/Integer
Some programming languages have ways of expressing integer literals in bases other than the normal base ten. Task Show how integer literals can be expressed in as many bases as your language allows. Note:   this should not involve the calling of any functions/methods, but should be interpreted by the compiler or...
#Elixir
Elixir
1234 #=> 1234 1_000_000 #=> 1000000 0010 #=> 10 0b111 #=> 7 0o10 #=> 8 0x1f #=> 31   0B10 #=> syntax error before: B10 0X10 #=> syntax error before: X10 0xFF #=> 255
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#COBOL
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. print-logic.   DATA DIVISION. LOCAL-STORAGE SECTION. 01 result PIC 1 USAGE BIT.   LINKAGE SECTION. 01 a PIC 1 USAGE BIT. 01 b PIC 1 USAGE BIT.   PROCEDURE D...
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Oforth
Oforth
3.14 1.0e-12 0.13 1000.0 .22
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#PARI.2FGP
PARI/GP
[+-]?((\d*\.\d+\b)|(\d+(\.\d*)?[Ee][+-]?\d+\b)|-?(\.\d+[Ee][+-]?\d+\b)|(\d+\.))
http://rosettacode.org/wiki/Literals/Floating_point
Literals/Floating point
Programming languages have different ways of expressing floating-point literals. Task Show how floating-point literals can be expressed in your language: decimal or other bases, exponential notation, and any other special features. You may want to include a regular expression or BNF/ABNF/EBNF defining allowable fo...
#Pascal
Pascal
1.345 -0.5345 5.34e-34
http://rosettacode.org/wiki/Long_year
Long year
Most years have 52 weeks, some have 53, according to ISO8601. Task Write a function which determines if a given year is long (53 weeks) or not, and demonstrate it.
#Scala
Scala
import java.time.temporal.TemporalAdjusters.firstInMonth import java.time.temporal.{ChronoField, IsoFields} import java.time.{DayOfWeek, LocalDate, Month}   import scala.util.{Failure, Try}   private object LongYear extends App { private val (currentCentury, maxWeekNumber) = (LocalDate.now().getYear / 100, ChronoFiel...
http://rosettacode.org/wiki/Long_primes
Long primes
A   long prime   (as defined here)   is a prime number whose reciprocal   (in decimal)   has a   period length   of one less than the prime number. Long primes   are also known as:   base ten cyclic numbers   full reptend primes   golden primes   long period primes   maximal period primes   proper primes A...
#PureBasic
PureBasic
#MAX=64000 If OpenConsole()=0 : End 1 : EndIf   Dim p.b(#MAX) : FillMemory(@p(),#MAX,#True,#PB_Byte) For n=2 To Int(Sqr(#MAX))+1 : If p(n) : m=n*n : While m<=#MAX : p(m)=#False : m+n : Wend : EndIf : Next   Procedure.i periodic(v.i) r=1 : Repeat : r=(r*10)%v : c+1 : If r<=1 : ProcedureReturn c : EndIf : ForEver EndPr...
http://rosettacode.org/wiki/Loop_over_multiple_arrays_simultaneously
Loop over multiple arrays simultaneously
Task Loop over multiple arrays   (or lists or tuples or whatever they're called in your language)   and display the   i th   element of each. Use your language's   "for each"   loop if it has one, otherwise iterate through the collection in order with some other loop. For this example, loop over the arrays: ...
#Diego
Diego
set_namespace(rosettacode);   add_mat(myMatrix)_row(a,b,c)_row(A,B,C)_row(1,2,3); add_var(output,columnArray);   with_mat(myMatrix)_foreach()_bycol()_var(columnArray) with_var(output)_append()_flat([columnArray])_append(\n); ;   me_msg([output]);   reset_namespace[];
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Factor
Factor
[ [ 20 random [ . ] [ 10 = [ return ] when ] bi 20 random . t ] loop ] with-return
http://rosettacode.org/wiki/Loops/Break
Loops/Break
Task Show a loop which prints random numbers (each number newly generated each loop) from 0 to 19 (inclusive). If a number is 10, stop the loop after printing it, and do not generate any further numbers. Otherwise, generate and print a second random number before restarting the loop. If the number 10 is never gener...
#Fantom
Fantom
  class ForBreak { public static Void main () { while (true) { a := Int.random(0..19) echo (a) if (a == 10) break echo (Int.random(0..19)) } } }  
http://rosettacode.org/wiki/Longest_common_subsequence
Longest common subsequence
Introduction Define a subsequence to be any output string obtained by deleting zero or more symbols from an input string. The Longest Common Subsequence (LCS) is a subsequence of maximum length common to two or more strings. Let A ≡ A[0]… A[m - 1] and B ≡ B[0]… B[n - 1], m < n be strings drawn from an alphabet Σ of ...
#Icon_and_Unicon
Icon and Unicon
procedure main() LCSTEST("thisisatest","testing123testing") LCSTEST("","x") LCSTEST("x","x") LCSTEST("beginning-middle-ending","beginning-diddle-dum-ending") end   link strings   procedure LCSTEST(a,b) #: helper to show inputs and results write("lcs( ",image(a),", ",image(b)," ) = ",image(res := lcs(a,b))) return re...
http://rosettacode.org/wiki/Look-and-say_sequence
Look-and-say sequence
The   Look and say sequence   is a recursively defined sequence of numbers studied most notably by   John Conway. The   look-and-say sequence   is also known as the   Morris Number Sequence,   after cryptographer Robert Morris,   and the puzzle   What is the next number in the sequence 1,   11,   21,   1211,   11122...
#Delphi
Delphi
\util.g   proc nonrec look_and_say(*char inp, outp) void: char cur; byte count; channel output text outch; open(outch, outp); while cur := inp*; cur ~= '\e' do count := 1; while inp := inp + 1; inp* = cur do count := count + 1 od...
http://rosettacode.org/wiki/Longest_string_challenge
Longest string challenge
Background This "longest string challenge" is inspired by a problem that used to be given to students learning Icon. Students were expected to try to solve the problem in Icon and another language with which the student was already familiar. The basic problem is quite simple; the challenge and fun part came through th...
#Yabasic
Yabasic
  data "a", "bb", "ccc", "ddd", "ee", "f", "ggg", "~"   do read test$ if test$ = "~" then break : fi if len(test$) > len(test1$) then test1$ = test$ test2$ = test1$ + chr$(10) elsif len(test$) = len(test1$) then test2$ = test2$ + test$ + chr$(10) end if loop   print(test2$...
http://rosettacode.org/wiki/Longest_string_challenge
Longest string challenge
Background This "longest string challenge" is inspired by a problem that used to be given to students learning Icon. Students were expected to try to solve the problem in Icon and another language with which the student was already familiar. The basic problem is quite simple; the challenge and fun part came through th...
#zkl
zkl
fcn longer(a,b){ //-->0,1,2 (same, a longer, b longer) while(a and b){a=a.del(0); b=b.del(0);} if (not a and not b) return(0); // a & b same length if(a) return(1); // a is longer 2 // b is longer }   text:=a:=ask("text: ").strip(); while(b:=ask("text: ").strip()){ switch(longer(a,b)){ case(0){...
http://rosettacode.org/wiki/Longest_increasing_subsequence
Longest increasing subsequence
Calculate and show here a longest increasing subsequence of the list: { 3 , 2 , 6 , 4 , 5 , 1 } {\displaystyle \{3,2,6,4,5,1\}} And of the list: { 0 , 8 , 4 , 12 , 2 , 10 , 6 , 14 , 1 , 9 , 5 , 13 , 3 , 11 , 7 , 15 } {\displaystyle \{0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15\}} Note that a list may have m...
#Prolog
Prolog
lis(In, Out) :- % we ask Prolog to find the longest sequence aggregate(max(N,Is), (one_is(In, [], Is), length(Is, N)), max(_, Res)), reverse(Res, Out).     % we describe the way to find increasing subsequence one_is([], Current, Current).     one_is([H | T], Current, Final) :- ( Current = [], one_is(T, [H], Final...
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#jq
jq
reduce range(1;11) as $i (""; . + "\($i)" + (if $i % 5 == 0 then "\n" else ", " end))
http://rosettacode.org/wiki/Loops/Continue
Loops/Continue
Task Show the following output using one loop. 1, 2, 3, 4, 5 6, 7, 8, 9, 10 Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while...
#Jsish
Jsish
/* Loop/continue in jsish */ for (var i = 1; i <= 10; i++) { printf("%d", i); if (i % 5 == 0) { printf("\n"); continue; } printf(", "); }
http://rosettacode.org/wiki/Longest_common_substring
Longest common substring
Task Write a function that returns the longest common substring of two strings. Use it within a program that demonstrates sample output from the function, which will consist of the longest common substring between "thisisatest" and "testing123testing". Note that substrings are consecutive characters within a string....
#Raku
Raku
sub createSubstrings( Str $word --> Array ) { my $length = $word.chars ; my @substrings ; for (0..$length - 1) -> $start { for (1..$length - $start) -> $howmany { @substrings.push( $word.substr( $start , $howmany ) ) ; } } return @substrings ; }   sub findLongestCommon( Str $first , Str $se...
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...
#Quackery
Quackery
[ 1 & ] is odd ( n --> b )   [ [] swap [ 10 /mod rot join swap dup 0 = until ] drop ] is digits ( n --> [ )   [ [] [] rot dup size odd dip [ witheach [ nested join swap ] ] not if swap ] is unzip ( [ --> [ [ ...
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...
#Tcl
Tcl
while true { puts SPAM } # or for {} 1 {} { puts 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...
#TI-83_BASIC
TI-83 BASIC
   :Lbl 1  :Disp "SPAM  :Goto 1  
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...
#TI-89_BASIC
TI-89 BASIC
Loop Disp "SPAM" EndLoop
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...
#SAS
SAS
data _null_; n=1024; do while(n>0); put n; n=int(n/2); end; run;
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...
#Sather
Sather
class MAIN is main is i ::= 1024; loop while!(i > 0); #OUT + i + "\n"; i := i / 2; end; end; 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...
#Tcl
Tcl
for {set i 10} {$i >= 0} {incr i -1} { puts $i } # puts "We have liftoff!"
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...
#Trith
Trith
10 inc iota reverse [print] each
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...
#PHP
PHP
$val = 0; do { $val++; print "$val\n"; } while ($val % 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...
#Picat
Picat
go => N = 0, do N := N+1, println(N) while (N 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. ...
#hexiscript
hexiscript
for let i 1; i <= 5; i++ for let j 1; j <= i; j++ print "*" endfor println "" endfor
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...
#Nim
Nim
for x in countup(1, 10, 4): echo x
http://rosettacode.org/wiki/Long_multiplication
Long multiplication
Task Explicitly implement   long multiplication. This is one possible approach to arbitrary-precision integer algebra. For output, display the result of   264 * 264. Optionally, verify your result against builtin arbitrary precision support. The decimal representation of   264   is: 18,446,744,073,709,551,61...
#Crystal
Crystal
require "big"   a = 2.to_big_i ** 64   puts "#{a} * #{a} = #{a*a}"  
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#F.23
F#
  let n= 'N' let i="Name=\"Nigel Galloway\"\n" let g= @"Name=""Nigel Galloway""\n" let e="Nigel Galloway" let l= """Name="Nigel Galloway"\n""" printfn "%c\n%s\n%s\n%s\n%s" n i g e l  
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#Factor
Factor
CHAR: a