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/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...
#PowerShell
PowerShell
$n = 0 do { $n++ $n } while ($n % 6 -ne 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. ...
#Icon_and_Unicon
Icon and Unicon
procedure main() every i := 1 to 5 do { every 1 to i do writes("*") write() } 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...
#OCaml
OCaml
# let for_step a b step fn = let rec aux i = if i <= b then begin fn i; aux (i+step) end in aux a ;; val for_step : int -> int -> int -> (int -> 'a) -> unit = <fun>   # for_step 0 8 2 (fun i -> Printf.printf " %d\n" i) ;; 0 2 4 6 8 - : unit = ()
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...
#Delphi
Delphi
  program Long_multiplication;   {$APPTYPE CONSOLE}   uses System.SysUtils;   type TLongMul = record private function Add(x, y: TArray<byte>): TArray<byte>; function ByteToString(b: TArray<byte>): Ansistring; function d(b: byte): Byte; function mulDigit(x: TArray<byte>; y: byte): TArray<byte>; ...
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...
#FurryScript
FurryScript
IsChar('a'); # true IsString("abc"); # true IsString('a'); # false IsChar("a"); # false
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...
#GAP
GAP
IsChar('a'); # true IsString("abc"); # true IsString('a'); # false IsChar("a"); # false
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...
#Fennel
Fennel
;; Fennel, like Lua, supports base 10 and hex literals (with a leading 0x). 1234  ;1234 0x1234  ;4660   ;; Optionally, underscores can be used to split numbers into readable chunks. 123_456_789  ;123456789 0x1234_5678  ;305419896
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...
#Forth
Forth
HEX FEEDFACE 2 BASE ! 1011001 DECIMAL 1234 : mask var @ [ base @ hex ] 3fff and [ base ! ] var ! ;
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 |...
#DWScript
DWScript
var a := True; var b := False;   Print('a = '); PrintLn(a); Print('b = '); PrintLn(b);   Print('a AND b: '); PrintLn(a AND b);   Print('a OR b: '); PrintLn(a OR b);   Print('NOT a: '); PrintLn(NOT a);   Print('a XOR b: '); PrintLn(a XOR b);
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...
#Raku
Raku
2e2 # same as 200e0, 2e2, 200.0e0 and 2.0e2 6.02e23 -2e48 1e-9 1e0
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...
#REXX
REXX
something = 127 something = '127' /*exactly the same as the above. */ something = 1.27e2 something = 1.27E2 something = 1.27E+2 something = ' + 0001.27e+00000000000000002 '
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...
#Ruby
Ruby
2.3 // Normal floating point literal 3. // Equivalent to 3.0 (3 would be interpreted as an integer) 2f64 // The type (in this case f64, a 64-bit floating point number) may be appended to the value 1_000.2_f32 // Underscores may appear anywhere in the number for clarity.
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.
#Visual_Basic
Visual Basic
Option Explicit   Function IsLongYear(ByVal Year As Integer) As Boolean Select Case vbThursday Case VBA.DatePart("w", VBA.DateSerial(Year, 1, 1)), _ VBA.DatePart("w", VBA.DateSerial(Year, 12, 31)) IsLongYear = True End Select End Function   Sub Main() 'test Dim l As Long For l = 1990 To 2021 Sele...
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.
#Wren
Wren
import "/date" for Date   var centuries = ["20th", "21st", "22nd"] var starts = [1900, 2000, 2100] for (i in 0...centuries.count) { var longYears = [] System.print("\nLong years in the %(centuries[i]) century:") for (j in starts[i]...starts[i]+100) { var t = Date.new(j, 12, 28) if (t.weekOfY...
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...
#REXX
REXX
/*REXX pgm calculates/displays base ten long primes (AKA golden primes, proper primes,*/ /*───────────────────── maximal period primes, long period primes, full reptend primes).*/ parse arg a /*obtain optional argument from the CL.*/ if a='' | a="," then a= '500 -500 -1000 -2000 ...
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: ...
#Efene
Efene
@public run = fn () { lists.foreach(fn ((A, B, C)) { io.format("~s~n", [[A, B, C]]) }, lists.zip3("abc", "ABC", "123")) }  
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...
#GML
GML
while(1) { a = floor(random(19)) show_message(string(a)) if(a = 10) break b = floor(random(19)) show_message(string(a)) }  
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...
#Go
Go
package main   import "fmt" import "math/rand" import "time"   func main() { rand.Seed(time.Now().UnixNano()) for { a := rand.Intn(20) fmt.Println(a) if a == 10 { break } b := rand.Intn(20) fmt.Println(b) } }
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 ...
#jq
jq
def lcs(xstr; ystr): if (xstr == "" or ystr == "") then "" else xstr[0:1] as $x | xstr[1:] as $xs | ystr[1:] as $ys | if ($x == ystr[0:1]) then ($x + lcs($xs; $ys)) else lcs(xstr; $ys) as $one | lcs($xs; ystr) as $two | if ($one|length) > ($two|length) then $one else $two 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...
#Elixir
Elixir
defmodule LookAndSay do def next(n) do Enum.chunk_by(to_char_list(n), &(&1)) |> Enum.map(fn cl=[h|_] -> Enum.concat(to_char_list(length cl), [h]) end) |> Enum.concat |> List.to_integer end   def sequence_from(n) do Stream.iterate n, &(next/1) end   def main([start_str|_]) do {start_val...
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...
#REXX
REXX
/*REXX program finds & displays the longest increasing subsequence from a list of #'s.*/ $.=; $.1= 3 2 6 4 5 1 /*define the 1st list to be examined. */ $.2= 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 /* " " 2nd " " " " */   do j=1 while $.j\==''; say ...
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...
#Lisaac
Lisaac
1.to 10 do { i : INTEGER; i.print; (i % 5 = 0).if { '\n'.print; } else { ','.print; }; };
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...
#LiveCode
LiveCode
repeat with n = 1 to 10 put n if n is 5 then put return if n < 10 and n is not 5 then put "," end repeat
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....
#Sidef
Sidef
func createSubstrings(String word) -> Array { gather { combinations(word.len+1, 2, {|i,j| take(word.substr(i, j-i)) }) } }   func findLongestCommon(String first, String second) -> String { createSubstrings(first) & createSubstrings(second) -> max_by { .len } }   say findLongestCommon("thisisates...
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....
#Swift
Swift
func lComSubStr< S0: Sliceable, S1: Sliceable, T: Equatable where S0.Generator.Element == T, S1.Generator.Element == T, S0.Index.Distance == Int, S1.Index.Distance == Int >(w1: S0, _ w2: S1) -> S0.SubSlice {   var (len, end) = (0, 0)   let empty = Array(Repeat(count: w2.count + 1, repeatedValue: 0)) ...
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...
#REXX
REXX
/*REXX program validates credit card numbers using the Luhn algorithm. */ #.=; #.1= 49927398716 /*the 1st sample credit card number. */ #.2= 49927398717 /* " 2nd " " " " */ #.3= 1234567812345678 ...
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...
#Vala
Vala
for(;;) stdout.printf("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...
#VAX_Assembly
VAX Assembly
0000 0000 1 .entry main,0 4D415053 8F DD 0002 2 pushl #^a"SPAM" ;string on stack 5E DD 0008 3 pushl sp ;reference to string 04 DD 000A 4 pushl #4 ;+length = descriptor ...
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...
#VBA
VBA
Do Debug.Print "SPAM" 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...
#Sidef
Sidef
var i = 1024 while (i > 0) { say i i //= 2 }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Simula
Simula
begin integer i; i:=1024; while i>0 do begin outint(i,5); i:=i//2-1 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...
#VBA
VBA
For i = 10 To 0 Step -1 Debug.Print i Next 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...
#Vedit_macro_language
Vedit macro language
for (#1 = 10; #1 >= 0; #1--) { Num_Type(#1) }
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...
#Prolog
Prolog
  % initial condition do(0):- write(0),nl,do(1).   % control condition do(V):- 0 is mod(V,6), !, fail.   % loop do(V) :- write(V),nl, Y is V + 1, do(Y).   wloop :- do(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. ...
#Inform_7
Inform 7
repeat with length running from 1 to 5: repeat with N running from 1 to length: say "*"; say line break;
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...
#Octave
Octave
for i = 1:2:10 disp(i) endfor
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...
#EchoLisp
EchoLisp
  (lib 'math) ;; for poly multiplication   ;; convert string of decimal digits to polynomial ;; "1234" → x^3 +2x^2 +3x +4 ;; least-significant digit first (define (string->long N) (reverse (map string->number (string->list N))))   ;; convert polynomial to string (define (long->string N) (if (pair? N) (string-appen...
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...
#gecho
gecho
'a outascii
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...
#Go
Go
ch := 'z' ch = 122 // or 0x7a or 0172 or any other integer literal ch = '\x7a' // \x{2*hex} ch = '\u007a' // \u{4*hex} ch = '\U0000007a' // \U{8*hex} ch = '\172' // \{3*octal}
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...
#Fortran
Fortran
program IntegerLiteral   implicit none integer, parameter :: dec = 727 integer, parameter :: hex = Z'2d7' integer, parameter :: oct = O'1327' integer, parameter :: bin = B'1011010111'   print *, dec, hex, oct, bin   end program IntegerLiteral
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...
#FreeBASIC
FreeBASIC
' FB 1.05.0 Win64   ' The following all print 64 to the console   ' integer literals of unspecified type - actual type is inferred from size or context (8, 16, 32 or 64 bit signed/unsigned) Print 64 '' Decimal literal Print &H40 '' Hexadecimal literal Print &O100 '' Octal Literal Print &B1000000 '' Bin...
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 |...
#Dyalect
Dyalect
var a = true var b = false print("a and b is \(a && b)") print("a or b is \(a || b)") print("Not a is \(!a)")
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 |...
#D.C3.A9j.C3.A0_Vu
Déjà Vu
showbool a b:  !.( a b or a b and a b xor a b not a )   for a in [ false true ]: for b in [ false true ]: showbool a b
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...
#Rust
Rust
2.3 // Normal floating point literal 3. // Equivalent to 3.0 (3 would be interpreted as an integer) 2f64 // The type (in this case f64, a 64-bit floating point number) may be appended to the value 1_000.2_f32 // Underscores may appear anywhere in the number for clarity.
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...
#Scala
Scala
1. //Double equal to 1.0 1.0 //Double, a 64-bit IEEE-754 floating point number (equivalent to Java's double primitive type) 2432311.7567374 //Double 1.234E-10 //Double 1.234e-10 //Double 758832d //Double 728832f //32-bit IEEE-754 floating point number (equivalent to Java's float primitive type) 1.0f //Float 758832D //...
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...
#Scheme
Scheme
  .2 ; 0.2 2. ; 2.0 2e3 ; 2000 2.+3.i ; complex floating-point number   ; in Scheme, floating-point numbers are inexact numbers (inexact? 2.) ; #t (inexact? 2) ; #f
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.
#XPL0
XPL0
  \Long year code Rem=2, CrLf=9, IntIn=10, IntOut=11, Text=12, Clear=40; integer S, E, Y;   function integer Weekday(Y); \Weekday of Y-12-31, 0 Sunday integer Y; return Rem((Y + Y / 4 - Y / 100 + Y / 400) / 7);   function integer IsLongYear(Y); integer Y; return 4 = Weekday(Y) ! 3 = Weekday(Y - 1);   begi...
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.
#zkl
zkl
fcn isLongYear(y){ Time.Date.weeksInYear(y)==53 } foreach nm,y in (T(T("20th",1900), T("21st",2000), T("22nd",2100))){ println("\nLong years in the %s century:\n%s".fmt(nm, [y..y+99].filter(isLongYear).concat(" "))); }
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...
#Ruby
Ruby
System: I7-6700HQ, 3.5 GHz, Linux Kernel 5.6.17 Run as: $ ruby longprimes.rb
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...
#Rust
Rust
// main.rs // References: // https://en.wikipedia.org/wiki/Full_reptend_prime // https://en.wikipedia.org/wiki/Primitive_root_modulo_n#Finding_primitive_roots   mod bit_array; mod prime_sieve;   use prime_sieve::PrimeSieve;   fn modpow(mut base: usize, mut exp: usize, n: usize) -> usize { if n == 1 { return...
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: ...
#Eiffel
Eiffel
  example (a_array: READABLE_INDEXABLE [BOUNDED [ANY]]): STRING -- Assemble output for a 2-dim array in `a_array' require non_zero: ∀ nzitem:a_array ¦ nzitem.count > 0 local min_count: INTEGER do ⟳ v_item:a_array ¦ min_count := if min_count = 0 then v_item.count else v_item.count.min (...
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...
#Groovy
Groovy
final random = new Random()   while (true) { def random1 = random.nextInt(20) print random1 if (random1 == 10) break print ' ' println random.nextInt(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 ...
#Julia
Julia
longest(a::String, b::String) = length(a) ≥ length(b) ? a : b   """ julia> lcsrecursive("thisisatest", "testing123testing") "tsitest" """ # Recursive function lcsrecursive(xstr::String, ystr::String) if length(xstr) == 0 || length(ystr) == 0 return "" end   x, xs, y, ys = xstr[1], xstr[2:end], ystr[...
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...
#Erlang
Erlang
-module(str). -export([look_and_say/1, look_and_say/2]).   %% converts a single number look_and_say([H|T]) -> lists:reverse(look_and_say(T,H,1,"")).   %% converts and accumulates as a loop look_and_say(_, 0) -> []; look_and_say(Start, Times) when Times > 0 -> [Start | look_and_say(look_and_say(Start), Times-1)].   ...
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...
#Ring
Ring
  # Project : Longest increasing subsequence   tests = [[3, 2, 6, 4, 5, 1], [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]] res = [] for x=1 to len(tests) lis(tests[x]) showarray(res) end   func lis(X) N = len(X) P = list(N) M = list(N) for nr = 1 to len(P) P[nr] = 0 n...
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...
#Lua
Lua
for i = 1, 10 do io.write( i ) if i % 5 == 0 then io.write( "\n" ) else io.write( ", " ) end 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...
#M2000_Interpreter
M2000 Interpreter
  Module Checkit { \\ A For {} loop For i=1 to 10 { Print i; if i mod 5 Else Print : continue Print ","; } Print i=11 \\ A For Next loop For i=1 to 10 Print i; if i mod 5 Else Print : continue Print ","; Ne...
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....
#VBA
VBA
  Function Longest_common_substring(string1 As String, string2 As String) As String Dim i As Integer, j As Integer, temp As String, result As String For i = 1 To Len(string1) For j = 1 To Len(string1) temp = Mid(string1, i, j) If InStr(string2, temp) Then If Len(temp)...
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....
#VBScript
VBScript
  Function lcs(string1,string2) For i = 1 To Len(string1) tlcs = tlcs & Mid(string1,i,1) If InStr(string2,tlcs) Then If Len(tlcs) > Len(lcs) Then lcs = tlcs End If Else tlcs = "" End If Next End Function   WScript.Echo lcs(WScript.Arguments(0),WScript.Arguments(1))  
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...
#Ring
Ring
decimals(0)   test = ["49927398716", "49927398717", "1234567812345678", "1234567812345670"] for n = 1 to len(test) see test[n] + " -> " + cardtest(test[n]) + nl next   func cardtest(numstr) revstring = revstr(numstr) s1 = revodd(revstring) s2 = reveven(revstring) s3 =right(string(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...
#VBScript
VBScript
Do WScript.Echo("SPAM") Loop
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within l...
#Vedit_macro_language
Vedit macro language
while (1) { Message("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...
#Visual_Basic
Visual Basic
Do Debug.Print("SPAM") 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...
#Sinclair_ZX81_BASIC
Sinclair ZX81 BASIC
10 LET I=1024 20 IF I=0 THEN GOTO 60 30 PRINT I 40 LET I=INT (I/2) 50 GOTO 20
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...
#Slate
Slate
#n := 1024. [n isPositive] whileTrue: [inform: number printString. 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...
#Verilog
Verilog
  module main; integer i;   initial begin   for(i = 10; i >= 0; i = i - 1) $write(i); $finish ; end endmodule  
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...
#Visual_Basic_.NET
Visual Basic .NET
For i = 10 To 0 Step -1 Console.WriteLine(i) Next
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...
#PureBasic
PureBasic
x=0 Repeat x+1 Debug x Until x%6=0
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Python
Python
val = 0 while True: val +=1 print val if val % 6 == 0: break
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. ...
#J
J
]\ '*****'
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...
#Oforth
Oforth
1 100 2 step: i [ i 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...
#Openscad
Openscad
/* Loop from 3 to 9 in steps of 2 */   for ( l = [3:2:9] ) { echo (l); } echo ("on a double white line.");
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...
#Euphoria
Euphoria
constant base = 1000000000   function atom_to_long(atom a) sequence s s = {} while a>0 do s = append(s,remainder(a,base)) a = floor(a/base) end while return s end function   function long_mult(object a, object b) sequence c if atom(a) then a = atom_to_long(a) end ...
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...
#Groovy
Groovy
def string = 'Able was I'
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...
#Haskell
Haskell
"abcdef" == "abc\ \def"   "abc\ndef" == "abc\n\ \def"
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...
#Frink
Frink
  123456789123456789 // (a number in base 10) 123_456_789_123_456_789 // (the same number in base 10 with underscores for readability) 1 quadrillion // (named numbers are fine in Frink.) 1ee39 // (exact exponent, an integer with exact value 10^39) 6.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...
#FutureBasic
FutureBasic
window 1   printf @" Decimal: %ld", 100 printf @" Hexadecimal: %x", 100 printf @" Octal: %o", 100 print @" Binary: "; bin$(100)   HandleEvents
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 |...
#E
E
def logicalOperations(a :boolean, b :boolean) { return ["and" => a & b, "or" => a | b, "not" => !a, "xor" => a ^ b] }
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...
#Seed7
Seed7
  3.14159265358979 1.0E-12 0.1234  
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...
#Sidef
Sidef
say 1.234; say .1234; say 1234e-5; say 12.34e5;
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...
#Smalltalk
Smalltalk
2.0 45e6 45e+6 78e-9 1.2E34
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...
#Scala
Scala
object LongPrimes extends App { def primeStream = LazyList.from(3, 2) .filter(p => (3 to math.sqrt(p).ceil.toInt by 2).forall(p % _ > 0))   def longPeriod(p: Int): Boolean = { val mstart = 10 % p @annotation.tailrec def iter(mod: Int, period: Int): Int = { val mod1 = ...
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: ...
#Ela
Ela
open monad io list imperative   xs = zipWith3 (\x y z -> show x ++ show y ++ show z) ['a','b','c'] ['A','B','C'] [1,2,3]   print x = do putStrLn x   print_and_calc xs = do xss <- return xs return $ each print xss   print_and_calc xs ::: IO
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...
#GW-BASIC
GW-BASIC
10 NUM = 0 20 WHILE NUM <> 10 30 NUM = INT(RND * 20) 40 PRINT NUM 50 WEND
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...
#Harbour
Harbour
PROCEDURE Loop()   LOCAL n   DO WHILE .T. ? n := hb_RandomInt( 0, 19 ) IF n == 10 EXIT ENDIF ? hb_RandomInt( 0, 19 ) ENDDO   RETURN
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 ...
#Kotlin
Kotlin
// version 1.1.2   fun lcs(x: String, y: String): String { if (x.length == 0 || y.length == 0) return "" val x1 = x.dropLast(1) val y1 = y.dropLast(1) if (x.last() == y.last()) return lcs(x1, y1) + x.last() val x2 = lcs(x, y1) val y2 = lcs(x1, y) return if (x2.length > y2.length) x2 else y...
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...
#ERRE
ERRE
  PROGRAM LOOK   PROCEDURE LOOK_AND_SAY(N$->N$) LOCAL I%,J%,C$,O$ I%=1 REPEAT C$=MID$(N$,I%,1) J%=I%+1 WHILE MID$(N$,J%,1)=C$ DO J%+=1 END WHILE O$+=MID$(STR$(J%-I%),2)+C$ I%=J% UNTIL I%>LEN(N$) N$=O$ END PROCEDURE   BEGIN NUM...
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...
#Ruby
Ruby
Node = Struct.new(:val, :back)   def lis(n) pileTops = [] # sort into piles for x in n # binary search low, high = 0, pileTops.size-1 while low <= high mid = low + (high - low) / 2 if pileTops[mid].val >= x high = mid - 1 else low = mid + 1 end end i = l...
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...
#Maple
Maple
for i from 1 to 10 do printf( "%d", i ); if irem( i, 5 ) = 0 then printf( "\n" ); next end if; printf( ", " ) end do:
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
tmp = ""; For[i = 1, i <= 10, i++, tmp = tmp <> ToString[i]; If[Mod[i, 5] == 0, tmp = tmp <> "\n"; , tmp = tmp <> ", "; ]; ]; Print[tmp]
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....
#Wren
Wren
var lcs = Fn.new { |a, b| var la = a.count var lb = b.count var lengths = List.filled(la * lb, 0) var greatestLength = 0 var output = "" var i = 0 for (x in a) { var j = 0 for (y in b) { if (x == y) { lengths[i*lb + j] = (i == 0 || j == 0) ? 1 : le...
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...
#Ruby
Ruby
def luhn_valid?(str) str.scan(/\d/).reverse #using str.to_i.digits fails for cases with leading zeros .each_slice(2) .sum { |i, k = 0| i.to_i + ((k.to_i)*2).digits.sum } .modulo(10).zero? end   ["49927398716", "49927398717", "1234567812345678", "1234567812345670"].map{ |i| luhn_valid?(...
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...
#Visual_Basic_.NET
Visual Basic .NET
Do Console.WriteLine("SPAM") Loop
http://rosettacode.org/wiki/Loops/Infinite
Loops/Infinite
Task Print out       SPAM       followed by a   newline   in an infinite loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For with a specified step   Loops/Foreach   Loops/Increment loop index within l...
#Vlang
Vlang
fn main() { for { 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...
#Wart
Wart
repeat :forever prn "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...
#Smalltalk
Smalltalk
[s atEnd] whileFalse: [s next. ...]. [foo notNil] whileTrue: [s next. ...]. [...] doWhile: [ ... someBooleanExpression ]. [...] doUntil: [ ... someBooleanExpression ]. [:exit | ... cold ifTrue:[exit value]. ...] loopWithExit
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...
#Sparkling
Sparkling
var i = 1024; while i > 0 { print(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...
#Vlang
Vlang
fn main() { for i := 10; i >= 0; i-- { print('$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...
#Wart
Wart
for i 10 (i >= 0) --i prn i
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#QB64
QB64
DO PRINT n n = n + 1 LOOP WHILE n MOD 6 <> 0