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/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...
#Plain_English
Plain English
To run: Start up. Show the halvings of 1024. Wait for the escape key. Shut down.   To show the halvings of a number: If the number is 0, exit. Convert the number to a string. Write the string to the console. Divide the number by 2. Repeat.
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...
#Pop11
Pop11
lvars i = 1024; while i > 0 do printf(i, '%p\n'); i div 2 -> i; 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...
#Rust
Rust
fn main() { for i in (0..=10).rev() { 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...
#Salmon
Salmon
for (x; 10; x >= 0; -1) x!;
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...
#Neko
Neko
/** Loops/Do-while in Neko Tectonics: nekoc loops-do-while.neko neko loops-do-while */   var index = 0; do { index += 1; $print(index, "\n"); } while (index % 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. ...
#FutureBasic
FutureBasic
window 1   long i, j   for i = 1 to 5 for j = 1 to i print @"*"; next print next   HandleEvents
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...
#MATLAB_.2F_Octave
MATLAB / Octave
for k = 0:10:100, printf('%d\n',k) end;
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...
#BASIC
BASIC
'PROGRAM : BIG MULTIPLICATION VER #1 'LRCVS 01.01.2010 'THIS PROGRAM SIMPLY MAKES A MULTIPLICATION 'WITH ALL THE PARTIAL PRODUCTS. '............................................................   DECLARE SUB A.INICIO (A$, B$) DECLARE SUB B.STORE (CAD$, N$) DECLARE SUB C.PIZARRA () DECLARE SUB D.ENCABEZADOS (A$, B$) DECL...
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...
#Bracmat
Bracmat
string "string" stri\t-\tng\r\n "-10" "+10" "{a*b}" ".,|&:+*^'$_" "[~/#<>%@?!-" string[~/#<>%@?!- "str; ing .,|&:+*^'$_ "
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...
#C
C
char ch = 'z';
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#REXX
REXX
/*REXX pgm illustrates how to code a list of words (named chemical elements */ /*──────────────────────── ordered by their atomic number) in a list format. */   $= 'hydrogen helium lithium beryllium boron carbon' , 'nitrogen oxygen fluorine neon sodium magnesi...
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#Ruby
Ruby
elements = %w( hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium scandium titanium vanadium chromium manganese i...
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#Standard_ML
Standard ML
(* space in \ .. \ is ignored *)   val elements = "\ \hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine \ \neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon \ \potassium calcium scandium titanium vanadium chromium manganese iron cobalt \ \nickel copper zinc gallium g...
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#Tcl
Tcl
set mtime "2021-05-10 16:11:50" set elements { hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium scandiu...
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...
#Lua
Lua
tree_list = {} offset = {}   function init() for i=1,32 do if i == 2 then table.insert(offset, 1) else table.insert(offset, 0) end end end   function append(t) local v = 1 | (t << 1) table.insert(tree_list, v) end   function show(t, l) while l > 0 do ...
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...
#BQN
BQN
¯5 ¯3000
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...
#Bracmat
Bracmat
#include <stdio.h>   int main(void) { printf("%s\n", ( (727 == 0x2d7) && (727 == 01327) ) ? "true" : "false");   return 0; }
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 |...
#APL
APL
LOGICALOPS←{(⍺∧⍵)(⍺∨⍵)(~⍺)(⍺⍲⍵)(⍺⍱⍵)(⍺≠⍵)}
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 |...
#ARM_Assembly
ARM Assembly
  /* ARM assembly Raspberry PI */ /* program logicoper.s */ /* Constantes */ .equ STDOUT, 1 .equ WRITE, 4 .equ EXIT, 1 /* Initialized data */ .data szMessResultAnd: .asciz "Result of And : \n" szMessResultOr: .asciz "Result of Or : \n" szMessResultEor: .asciz "Result of Exclusive Or : \n" szMessResultN...
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...
#Visual_Basic_.NET
Visual Basic .NET
For i = 1 To 10 Console.Write(i) If i = 10 Then Exit For Console.Write(", ") Next
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...
#Vlang
Vlang
fn main() { for i := 1; ; i++ { print(i) if i == 10 { break } print(", ") } }
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...
#GAP
GAP
-3.14 22.03e4 4.54e-5
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...
#gecho
gecho
  0.0 -1 -1.2 -1.4324 3 4 /  
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...
#Go
Go
0. 0.0 .0 1e3 1e-300 6.02E+23
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.
#Kotlin
Kotlin
  fun main() { val has53Weeks = { year: Int -> LocalDate.of(year, 12, 28).get(WeekFields.ISO.weekOfYear()) == 53 } println("Long years this century:") (2000..2100).filter(has53Weeks) .forEach { year -> print("$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.
#Logo
Logo
to div :x :y output int quotient :x :y end   to dec31_weekday :year output remainder (sum :year div :year 4 div :year -100 div :year 400) 7 end   to iso_long_year? :year output or 4 = dec31_weekday :year 3 = dec31_weekday difference :year 1 end   for [y 1995 2045 1] [if iso_long_year? :y [print :y]]
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...
#jq
jq
  def count(s): reduce s as $x (0; .+1);   # Is the input integer a prime? # "previous" should be a sorted array of consecutive primes # from 2 on that includes the greatest prime less than (.|sqrt) def is_prime(previous): . as $in | (($in + 1) | sqrt) as $sqrt | first(previous[] | if . > $sqrt then 1 ...
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...
#Julia
Julia
  using Primes   function divisors(n) f = [one(n)] for (p,e) in factor(n) f = reduce(vcat, [f*p^j for j in 1:e], init=f) end return length(f) == 1 ? [one(n), n] : sort!(f) end   function islongprime(p) for i in divisors(p-1) if powermod(10, i, p) == 1 return i + 1 == 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: ...
#C
C
#include <stdio.h>   char a1[] = {'a','b','c'}; char a2[] = {'A','B','C'}; int a3[] = {1,2,3};   int main(void) { for (int i = 0; i < 3; i++) { printf("%c%c%i\n", a1[i], a2[i], a3[i]); } }
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...
#Common_Lisp
Common Lisp
(loop for a = (random 20) do (print a) until (= a 10) do (print (random 20)))
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...
#D
D
import std.stdio, std.random;   void main() { while (true) { int r = uniform(0, 20); write(r, " "); if (r == 10) break; write(uniform(0, 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 ...
#Elixir
Elixir
defmodule LCS do def lcs(a, b) do lcs(to_charlist(a), to_charlist(b), []) |> to_string end   defp lcs([h|at], [h|bt], res), do: lcs(at, bt, [h|res]) defp lcs([_|at]=a, [_|bt]=b, res) do Enum.max_by([lcs(a, bt, res), lcs(at, b, res)], &length/1) end defp lcs(_, _, res), do: res |> Enum.reverse end   ...
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...
#C.2B.2B
C++
#include <iostream> #include <sstream> #include <string>   std::string lookandsay(const std::string& s) { std::ostringstream r;   for (std::size_t i = 0; i != s.length();) { auto new_i = s.find_first_not_of(s[i], i + 1);   if (new_i == std::string::npos) new_i = s.length();   ...
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...
#PureBasic
PureBasic
    Procedure.i ConsoleWrite(t.s) ; compile using /CONSOLE option OpenConsole() PrintN (t.s) CloseConsole() ProcedureReturn 1 EndProcedure   Procedure.i StdOut(t.s) ; compile using /CONSOLE option OpenConsole() Print(t.s) CloseConsole() ProcedureReturn 1...
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...
#Python
Python
import fileinput   # This returns True if the second string has a value on the # same index as the last index of the first string. It runs # faster than trimming the strings because it runs len once # and is a single index lookup versus slicing both strings # one character at a time. def longer(a, b): try: ...
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...
#Nim
Nim
proc longestIncreasingSubsequence[T](d: seq[T]): seq[T] = var l: seq[seq[T]] for i in 0 .. d.high: var x: seq[T] for j in 0 ..< i: if l[j][l[j].high] < d[i] and l[j].len > x.len: x = l[j] l.add x & @[d[i]] for x in l: if x.len > result.len: result = x   for d in [@[3,2,6,4,5,1]...
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...
#Fortran
Fortran
do i = 1, 10 write(*, '(I0)', advance='no') i if ( mod(i, 5) == 0 ) then write(*,*) cycle end if write(*, '(A)', advance='no') ', ' end do
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....
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
Print[LongestCommonSubsequence["thisisatest", "testing123testing"]];
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....
#Modula-2
Modula-2
MODULE LCS; FROM FormatString IMPORT FormatString; FROM Terminal IMPORT WriteString,WriteLn,Write,ReadChar;   PROCEDURE WriteSubstring(s : ARRAY OF CHAR; b,e : CARDINAL); VAR i : CARDINAL; BEGIN IF b=e THEN RETURN END; IF e>HIGH(s) THEN e := HIGH(s) END;   FOR i:=b TO e DO Write(s[i]) END END Wr...
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...
#Vala
Vala
void main() {   int[,] a = new int[10, 10]; bool broken = false; for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) a[i, j] = Random.int_range(0, 21) % 20 + 1;   for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { stdout.printf(" %d", a[i, j]); if (a[i, j] == 20) { ...
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...
#PL.2FI
PL/I
test: procedure options (main);   declare (cardnumber, rcn) character (20) varying; declare (i, k, s1, s2) fixed binary;   get edit (cardnumber) (L); cardnumber = trim(cardnumber); rcn = reverse(cardnumber); s1, s2 = 0; /* Sum the odd-numbered digits */ do i = 1 to length(rcn) by 2; s1 = s...
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...
#Run_BASIC
Run BASIC
[loop] print "Spam" :goto [loop]   while 1 print "Spam" wend
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...
#Rust
Rust
fn main() { loop { 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...
#S-lang
S-lang
forever print("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...
#PostScript
PostScript
1024 { dup 0 le  % check whether still greater than 0 { pop exit } % if not, exit the loop if dup =  % print the number 2 idiv  % divide by two } loop
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...
#PowerShell
PowerShell
[int]$i = 1024 while ($i -gt 0) { $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...
#Sather
Sather
class MAIN is main is i:INT; loop i := 10.downto!(0); #OUT + i + "\n"; 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...
#Scala
Scala
for(i <- 10 to 0 by -1) println(i) //or 10 to 0 by -1 foreach println
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...
#Nemerle
Nemerle
mutable x = 0; do { x++; WriteLine($"$x"); } while (x % 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. ...
#Gambas
Gambas
Public Sub Main() Dim i, j As Integer   For i = 1 To 5 For j = 1 To i Print "*"; Next Print Next   End
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...
#Maxima
Maxima
for i: 1 step 2 thru 10 do print(i); /* 1 3 5 7 */
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...
#MAXScript
MAXScript
for i = 0 to 10 by 2 do format "%\n" 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...
#Batch_File
Batch File
::Long Multiplication Task from Rosetta Code ::Batch File Implementation   @echo off call :longmul 18446744073709551616 18446744073709551616 answer echo(%answer% exit /b 0 rem The Hellish Procedure rem Syntax: call :longmul <n1> <n2> <variable to store product> :longmul setlocal enabledelayedexpansion rem Def...
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...
#C.23
C#
string path = @"C:\Windows\System32"; string multiline = @"Line 1. Line 2. Line 3.";
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...
#C.2B.2B
C++
auto strA = R"(this is a newline-separated raw string)";  
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#UNIX_Shell
UNIX Shell
  main() { elements=( hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium scandium titanium van...
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#Wren
Wren
import "/pattern" for Pattern   var elementStr = "hydrogen helium lithium beryllium boron carbon " + "nitrogen oxygen fluorine neon sodium magnesium " + "aluminum silicon phosphorous sulfur chlorine argon " + "potassium ...
http://rosettacode.org/wiki/Long_literals,_with_continuations
Long literals, with continuations
This task is about writing a computer program that has long literals   (character literals that may require specifying the words/tokens on more than one (source) line,   either with continuations or some other method, such as abutments or concatenations   (or some other mechanisms). The literal is to be in the form ...
#zkl
zkl
revisionDate:="2020-03-23"; elements:= #<<<" hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon potassium calcium scandium titanium ...
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...
#Mathematica_.2F_Wolfram_Language
Mathematica / Wolfram Language
Addbags[configs_List] := DeleteDuplicates[ Map[LexicographicSort, Catenate[AddbagAll /@ configs], \[Infinity]]] AddbagAll[config_] := Addbag[config, #] & /@ Position[config, bag[___], \[Infinity]] Addbag[config_, pos_] := ReplacePart[config, pos -> Append[Extract[config, pos], bag[]]] With[{n = 5}, Nest[Add...
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...
#Nim
Nim
import os, strformat, strutils   type Tree = int Trees = object list: seq[Tree] offsets: array[32, int]     func isOdd(n: int): bool = (n and 1) != 0     func append(trees: var Trees; tree: Tree) = trees.list.add(1 or tree shl 1)     proc show(tree: Tree; n: int) = var tree = tree var n = n while n ...
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...
#Perl
Perl
use strict; use warnings; use feature 'say';   sub bagchain { my($x, $n, $bb, $start) = @_; return [@$x] unless $n;   my @sets; $start //= 0; for my $i ($start .. @$bb-1) { my($c, $s) = @{$$bb[$i]}; push @sets, bagchain([$$x[0] + $c, $$x[1] . $s], $n-$c, $bb, $i) if $c <= $n } ...
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...
#C
C
#include <stdio.h>   int main(void) { printf("%s\n", ( (727 == 0x2d7) && (727 == 01327) ) ? "true" : "false");   return 0; }
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...
#C.23
C#
int a = 42; int b = 0x2a;
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 |...
#Arturo
Arturo
logic: function [a b][ print ["a AND b =" and? a b] print ["a OR b =" or? a b] print ["NOT a = " not? a] ]   logic true false
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 |...
#Asymptote
Asymptote
bool a = true; bool b = false;   write(a & b); write(a && b); //(with conditional evaluation of right-hand argument) write(a | b); write(a || b); //(with conditional evaluation of right-hand argument) write(a ^ b); write(!a);
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...
#Wart
Wart
for i 1 (i <= 10) ++i pr i if (i < 10) pr ", " (prn)
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...
#Wee_Basic
Wee Basic
print 1 "" for numbers=1 to 10 print 1 at numbers*3-2,0 numbers if numbers<>10 print 1 at numbers*3-1,0 "," endif end
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...
#Wren
Wren
for (i in 1..10) { System.write(i) System.write((i < 10) ? ", " : "\n") }
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...
#Groovy
Groovy
println 1.00f // float (IEEE-32) println 1.00d // double (IEEE-64) println 1.00 // BigDecimal (scaled BigInteger) println 1.00g // BigDecimal println 1.00e0 // BigDecimal   assert 1.00f instanceof Float assert 1.00d instanceof Double assert 1.00 instanceof BigDecimal assert 1.00g instanceof BigDecim...
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...
#Haskell
Haskell
main = print [0.1,23.3,35e-1,56E+2,14.67e1]  
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.
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
firstyear = 2000; lastyear = 2099; years = Range[firstyear, lastyear]; firstday = Table[DayName[{years[[n]], 01, 01}], {n, Length[years]}]; lastday = Table[DayName[{years[[n]], 12, 31}], {n, Length[years]}]; Table[If[years[[n]] >= 1582, If[firstday[[n]] == Thursday || lastday[[n]] == Thursday, Style[years[[n]] "...
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.
#Modula-2
Modula-2
MODULE LongYear; FROM InOut IMPORT WriteCard, WriteLn;   VAR year: CARDINAL;   PROCEDURE isLongYear(year: CARDINAL): BOOLEAN; PROCEDURE p(year: CARDINAL): CARDINAL; BEGIN RETURN (year + year DIV 4 - year DIV 100 + year DIV 400) MOD 7; END p; BEGIN RETURN (p(year) = 4) OR (p(year-1) = 3); END isL...
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...
#Kotlin
Kotlin
// Version 1.2.60   fun sieve(limit: Int): List<Int> { val primes = mutableListOf<Int>() val c = BooleanArray(limit + 1) // composite = true // no need to process even numbers var p = 3 var p2 = p * p while (p2 <= limit) { for (i in p2..limit step 2 * p) c[i] = true do { ...
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: ...
#C.23
C#
class Program { static void Main(string[] args) { char[] a = { 'a', 'b', 'c' }; char[] b = { 'A', 'B', 'C' }; int[] c = { 1, 2, 3 }; int min = Math.Min(a.Length, b.Length); min = Math.Min(min, c.Length); for (int i = 0; i < min; i++) Console.WriteLine(...
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...
#dc
dc
1 ss [s = seed of the random number generator]sz 0k [scale = 0]sz   [Function r: Push a random number from 0 to 20.]sz [ [2Q]SA [ [Formula (from POSIX) for random numbers of low quality.]sz ls 1103515245 * 12345 + 4294967296 % d ss [Compute next s]sz 65536 / [it = s / 65536]sz d 16 !>A [Break 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...
#Delphi
Delphi
program Project5;   {$APPTYPE CONSOLE}   var num:Integer; begin Randomize; while true do begin num:=Random(20); Writeln(num); if num=10 then break; end; end.    
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 ...
#Erlang
Erlang
  module(lcs). -compile(export_all).   lcs_length(S,T) -> {L,_C} = lcs_length(S,T,dict:new()), L.   lcs_length([]=S,T,Cache) -> {0,dict:store({S,T},0,Cache)}; lcs_length(S,[]=T,Cache) -> {0,dict:store({S,T},0,Cache)}; lcs_length([H|ST]=S,[H|TT]=T,Cache) -> {L,C} = lcs_length(ST,TT,Cache), {L+1,d...
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...
#Ceylon
Ceylon
shared void run() {   function lookAndSay(Integer|String input) {   variable value digits = if (is Integer input) then input.string else input; value builder = StringBuilder();   while (exists currentChar = digits.first) { if (exists index = digits.firstIndexWhere((char) => char ...
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...
#Racket
Racket
  #lang racket   (define (newline? c) (equal? c #\newline)) (define eof? eof-object?)   (let loop ([O '()] [C '(#\newline)] [rI '()] [rO '()] [rC '()]) (let* ([i (read-char)] [o (car C)] [i:rI (cons i rI)] [i:rC (cons i rC)]) (cond [(eof? i) (for-each write-char O)] [(and (newline? o) (newline? i)) ...
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...
#Raku
Raku
my $l = ''; # Sample longest string seen. my $a = ''; # Accumulator to save longest strings.   while get() -> $s { my $n = "$s\n"; if $n.substr($l.chars) { # Is new string longer? $a = $l = $n; # Reset accumulator. } elsif !$l.substr($n.chars) { # Same length? $a ~= $n; ...
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...
#Objective-C
Objective-C
#import <Foundation/Foundation.h>   @interface Node : NSObject { @public id val; Node *back; } @end   @implementation Node @end   @interface NSArray (LIS) - (NSArray *)longestIncreasingSubsequenceWithComparator:(NSComparator)comparator; @end   @implementation NSArray (LIS) - (NSArray *)longestIncreasingSubsequenceW...
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...
#FutureBasic
FutureBasic
include "NSLog.incl"   long num   for num = 1 to 10 if ( num mod 5 ) NSLog(@"%ld, \b",num) else NSLog(@"%ld",num) end if next   HandleEvents
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...
#Gambas
Gambas
Public Sub Main() Dim siCount As Short   For siCount = 1 To 10 Print siCount; If siCount <> 5 And siCount <> 10 Then Print ","; If siCount = 5 Then Print gb.NewLine; Next   End
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....
#Nim
Nim
# Longest common substring.   import sequtils   func lcs(a, b: string): string = var lengths = newSeqWith(a.len, newSeq[int](b.len)) var greatestLength = 0 for i, x in a: for j, y in b: if x == y: lengths[i][j] = if i == 0 or j == 0: 1 else: lengths[i - 1][j - 1] + 1 if lengths[i][j] > g...
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....
#Pascal
Pascal
  PROGRAM LongestCommonSubString.pas;   {$DEFINE DEBUGGING} {$IFDEF FPC} {$mode objfpc}{$H+}{$J-}{R+} {$ELSE} {$APPTYPE CONSOLE} {$ENDIF}   (*)   Free Pascal Compiler version 3.2.0 [2020/06/14] for x86_64 The free and readable alternative at C/C++ speeds compiles natively to almost any p...
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...
#VBA
VBA
Public Sub LoopsNested() Dim a(1 To 10, 1 To 10) As Integer Randomize For i = 1 To 10 For j = 1 To 10 a(i, j) = Int(20 * Rnd) + 1 Next j Next i For i = 1 To 10 For j = 1 To 10 If a(i, j) <> 20 Then Debug.Print a(i, j), Else ...
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...
#PL.2FM
PL/M
100H: BDOS: PROCEDURE(F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS; EXIT: PROCEDURE; GO TO 0; END EXIT; PRINT: PROCEDURE(S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;   LUHN: PROCEDURE(NUM) BYTE; DECLARE MAP DATA (0, 2, 4, 6, 8, 1, 3, 5, 7, 9); DECLARE (START, NUM, MASK, TOTAL) ADDRESS; DECLARE (C...
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...
#Salmon
Salmon
while (true) "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...
#Sather
Sather
class MAIN is main is loop #OUT + "Spam\n"; end; end; 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...
#Scala
Scala
while (true) println("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...
#Prolog
Prolog
while(0) :- !. while(X) :- writeln(X), X1 is X // 2, while(X1).
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...
#PureBasic
PureBasic
If OpenConsole()   x.i = 1024 While x > 0 PrintN(Str(x)) x / 2 Wend   Print(#CRLF$ + #CRLF$ + "Press ENTER to exit") Input() CloseConsole() EndIf
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...
#Scheme
Scheme
(do ((i 10 (- i 1))) ((< i 0)) (display i) (newline))
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...
#Scilab
Scilab
for i=10:-1:0 printf("%d\n",i) 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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols nobinary   say say 'Loops/Do-while'   i_ = 0 loop until i_ // 6 = 0 i_ = i_ + 1 say i_ 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...
#NewLISP
NewLISP
(let ((i 0)) (do-until (= 0 (% i 6)) (println (++ i))))
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. ...
#GAP
GAP
for i in [1 .. 5] do for j in [1 .. i] do Print("*"); od; Print("\n"); od;   # * # ** # *** # **** # *****
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...
#min
min
0 (dup 10 >=) 'pop (puts 2 +) () linrec
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...
#BBC_BASIC
BBC BASIC
INSTALL @lib$+"BB4WMAPMLIB" MAPM_DllPath$ = @lib$+"BB4WMAPM.DLL" PROCMAPM_Init   twoto64$ = "18446744073709551616" PRINT "2^64 * 2^64 = " ; FNMAPM_Multiply(twoto64$, twoto64$)
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...
#Clojure
Clojure
[\h \e \l \l \o] ; a vector of characters \uXXXX ; where XXXX is some hex Unicode code point \\ ; the backslash character literal