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/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...
#FreeBASIC
FreeBASIC
' version 08-01-2017 ' compile with: fbc -s console   Const As UInteger base_ = 1000000000 ' base 1,000,000,000   Function multiply(a1 As String, b1 As String) As String   Dim As String a = a1, b = b1   Trim(a) : Trim(b) ' remove spaces If Len(a) = 0 Or Len(b) = 0 Then Return "0"   If Len(a) + Len(b) >...
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...
#JavaScript
JavaScript
(function () { return "αβγδ 中间来点中文 🐫 אבגד" })();     (function() { return "\u03b1\u03b2\u03b3\u03b4 \u4e2d\u95f4\u6765\u70b9\u4e2d\u6587 \ud83d\udc2b \u05d0\u05d1\u05d2\u05d3"; })();
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...
#jq
jq
greet = "Hello" whom = "world" greet * ", " * whom * "."
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...
#HicEst
HicEst
U8 i; // 8 bit integer U16 i; // 16 bit integer U32 i; // 32 bit integer U64 i; // 64 bit integer
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...
#HolyC
HolyC
U8 i; // 8 bit integer U16 i; // 16 bit integer U32 i; // 32 bit integer U64 i; // 64 bit integer
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 |...
#Elm
Elm
  --Open cmd and elm-repl and directly functions can be created   --Creating Functions t=True f=False opand a b= a && b opor a b= a || b opnot a= not a   --Using the created Functions opand t f opor t f opnot f   --Output will be False, True and True of type Boolean! --end  
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 |...
#Erlang
Erlang
1> true and false. false 2> false or true. true 3> true xor false. true 4> not false. true 5> not (true and true). false
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...
#XBasic
XBasic
  PROGRAM "longprimes" VERSION "0.0002"   DECLARE FUNCTION Entry() INTERNAL FUNCTION Sieve(limit&, primes&[], count%) INTERNAL FUNCTION FindPeriod(n&)   FUNCTION Entry() DIM numbers&[7] numbers&[0] = 500 numbers&[1] = 1000 numbers&[2] = 2000 numbers&[3] = 4000 numbers&[4] = 8000 numbers&[5] = 16000 numb...
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: ...
#Euphoria
Euphoria
are.
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...
#Io
Io
loop( a := Random value(0,20) floor write(a) if( a == 10, writeln ; break) b := Random value(0,20) floor writeln(" ",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 ...
#M4
M4
define(`set2d',`define(`$1[$2][$3]',`$4')') define(`get2d',`defn($1[$2][$3])') define(`tryboth', `pushdef(`x',lcs(`$1',substr(`$2',1),`$1 $2'))`'pushdef(`y', lcs(substr(`$1',1),`$2',`$1 $2'))`'ifelse(eval(len(x)>len(y)),1, `x',`y')`'popdef(`x')`'popdef(`y')') define(`checkfirst', `ifelse(substr(...
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...
#FOCAL
FOCAL
01.10 A "HOW MANY",M 01.20 S B(0)=1;S B(1)=0 01.30 F Z=1,M;D 4;D 2 01.40 Q   02.10 S X=0;S Y=0 02.15 I (B(X)),2.5 02.17 S CN=0 02.20 S CN=CN+1 02.25 S X=X+1 02.30 I (FABS(B(X)-B(X-1))),2.2 02.35 S C(Y)=CN;S C(Y+1)=B(X-1) 02.40 S Y=Y+2 02.45 G 2.15 02.50 S C(Y)=0 02.55 F X=0,Y;S B(X)=C(X)   03.10 I (A-9)3.2;T "9";R 03.2...
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...
#Sidef
Sidef
func lis(a) { var l = a.len.of { [] } l[0] << a[0] for i in (1..a.end) { for j in ^i { if ((a[j] < a[i]) && (l[i].len < l[j].len+1)) { l[i] = [l[j]...] } } l[i] << a[i] } l.max_by { .len } }   say lis(%i<3 2 6 4 5 1>) say lis(%i<0 8 4 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...
#Neko
Neko
/** Loops/Continue in Neko Tectonics: nekoc loops-continue.neko neko loops-continue */   var index = 0;   while index < 10 { index += 1; $print(index); if $not($istrue(index % 5)) { $print("\n");   continue;   } $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...
#Nemerle
Nemerle
using System; using System.Console; using Nemerle.Imperative;   module Continue { Main() : void { foreach (i in [1 .. 10]) { Write(i); when (i % 5 == 0) {WriteLine(); continue;} Write(", "); } } }
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...
#Scheme
Scheme
(define luhn (lambda (n) (let loop ((number n) (index 0) (result 0)) (if (= 0 number) (= 0 (remainder result 10)) (loop (quotient number 10) (+ index 1) (+ result (if (even? index) (re...
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...
#Zoomscript
Zoomscript
var loop loop = 1 while ne loop 0 print "SPAM" println endwhile
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...
#Swift
Swift
var i = 1024 while i > 0 { println(i) i /= 2 }
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#Tailspin
Tailspin
  1024 -> \( <0~..> '$;$#10;' -> !OUT::write $ ~/ 2 -> # \) -> !VOID  
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...
#REXX
REXX
/*REXX program demonstrates a DO UNTIL construction. */ v=0 do until v//6==0 /*REXX // is the ÷ remainder.*/ v=v+1 say v end /*stick a fork in it, we're done.*/
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...
#Ring
Ring
  n = 0 While True n++ See n + nl if n % 6 = 0 exit ok end  
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. ...
#Jsish
Jsish
var i, j, s; for (i = 1; i <= 5; i += 1) { s = ''; for (j = 0; j < i; j += 1) s += '*'; puts(s); }
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...
#PHP
PHP
<?php foreach (range(2, 8, 2) as $i) echo "$i, "; echo "who do we appreciate?\n"; ?>
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...
#Go
Go
// Long multiplication per WP article referenced by task description. // That is, multiplicand is multiplied by single digits of multiplier // to form intermediate results. Intermediate results are accumulated // for the product. Used here is the abacus method mentioned by the // article, of summing intermediate resu...
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...
#JSON
JSON
greet = "Hello" whom = "world" greet * ", " * whom * "."
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...
#Julia
Julia
greet = "Hello" whom = "world" greet * ", " * whom * "."
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() L := [1, 2r10, 3r10, 4r10, 5r10, 6r10, 7r10, 8r10, 9r10, 10r10, 11r10, 12r10, 13r10, 14r10, 15r10, 16r10, 17r10, 18r10,19r10, 20r10, 21r10, 22r10, 23r10, 24r10, 25r10, 26r10, 27r10, 28r10, 29r10, 30r10, 31r10, 32r10, 33r10, 34r10, 35r10, 36r10]   every write(!L) end
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...
#J
J
10b123 16b123 8b123 20b123 2b123 1b123 0b123 100b123 99 0 0bsilliness 1 123 291 83 443 11 6 3 10203 99 0 1 28
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 |...
#Euphoria
Euphoria
procedure print_logic(integer a, integer b) printf(1,"a and b is %d\n", a and b) printf(1,"a or b is %d\n", a or b) printf(1,"a xor b is %d\n", a xor b) printf(1,"not a is %d\n", not a) end procedure
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 |...
#Excel
Excel
  =CONCATENATE($A1, " AND ", $B1, " is ", AND($A1,$B1))  
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...
#zkl
zkl
var [const] BN=Import("zklBigNum"); // libGMP primes,p := List.createLong(7_000), BN(3); // one big alloc vs lots of allocs while(p.nextPrime()<=64_000){ primes.append(p.toInt()) } // 6412 of them, skipped 2 primes.append(p.toInt()); // and one more so tail prime is >64_000   longPrimes:=primes.filter(fcn(p){ findPer...
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: ...
#F.23
F#
for c1,c2,n in Seq.zip3 ['a';'b';'c'] ['A';'B';'C'] [1;2;3] do printfn "%c%c%d" c1 c2 n
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...
#J
J
loopexample=: verb define while. 1 do. smoutput n=. ?20 if. 10=n do. return. end. smoutput ?20 end. )
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...
#Java
Java
import java.util.Random;   Random rand = new Random(); while(true){ int a = rand.nextInt(20); System.out.println(a); if(a == 10) break; int b = rand.nextInt(20); System.out.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 ...
#Maple
Maple
  > StringTools:-LongestCommonSubSequence( "thisisatest", "testing123testing" ); "tsitest"  
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...
#Forth
Forth
create buf1 256 allot create buf2 256 allot buf1 value src buf2 value dest   s" 1" src place   : append-run ( digit run -- ) dest count + tuck c! 1+ c! dest c@ 2 + dest c! ;   : next-look-and-say 0 dest c! src 1+ c@ [char] 0 ( digit run ) src count bounds do over i c@ = if 1+ else append-ru...
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...
#Standard_ML
Standard ML
fun lis cmp n = let val pile_tops = DynamicArray.array (length n, []) fun bsearch_piles x = let fun aux (lo, hi) = if lo > hi then lo else let val mid = (lo + hi) div 2 in if cmp (hd (DynamicArray.sub (pile_tops,...
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...
#NetRexx
NetRexx
/* NetRexx */ options replace format comments java crossref savelog symbols nobinary   say say 'Loops/Continue'   nul = '\-' loop i_ = 1 to 10 say i_.right(2) || nul if i_ // 5 = 0 then do say iterate i_ end say ', ' || nul   end i_  
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...
#NewLISP
NewLISP
(for (i 1 10) (print i) (if (= 0 (% i 5)) (println) (print ", ")))
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...
#sed
sed
# Split number into double evens and odds s/.*/&: / : split s/\([0-4]\)\([0-9]\):\(.*\) /:\1\1\3 \2/ s/\([5-9]\)\([0-9]\):\(.*\) /:1\1\1\3 \2/ t split   # Set up addition lookup table s/\([0-9]\)*:\(.*\) \(.*\)/\1\2\3:0123456789012345678/   : add s/\([0-9]\)0:/\1:/ s/\([0-9]\)1:\(.*\1.\{0\}\([0-9]\).*\)/\3:\2/ s/\([0-9...
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...
#Tcl
Tcl
set i 1024 while {$i > 0} { puts $i set i [expr {$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...
#Plain_TeX
Plain TeX
\newcount\rosetta \rosetta=1024 \loop \the\rosetta\endgraf \divide\rosetta by 2 \ifnum\rosetta > 0 \repeat \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...
#Ruby
Ruby
let mut x = 0;   loop { x += 1; println!("{}", x);   if x % 6 == 0 { break; } }
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...
#Rust
Rust
let mut x = 0;   loop { x += 1; println!("{}", x);   if x % 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. ...
#Julia
Julia
  for i in 1:5 for j in 1:i print("*") end println() 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...
#PicoLisp
PicoLisp
(for (N 1 (> 10 N) (+ N 2)) (printsp N) )
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...
#Haskell
Haskell
import Data.List (transpose, inits) import Data.Char (digitToInt)   longmult :: Integer -> Integer -> Integer longmult x y = foldl1 ((+) . (10 *)) (polymul (digits x) (digits y))   polymul :: [Integer] -> [Integer] -> [Integer] polymul xs ys = sum <$> transpose (zipWith (<>) (inits $ repeat 0) ...
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...
#Kotlin
Kotlin
// version 1.0.6   fun main(args: Array<String>) { val cl = 'a' // character literal - can contain escaped character val esl = "abc\ndef" // escaped string literal - can contain escaped character(s) val rsl = """ This is a raw string literal which does not treat esca...
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...
#LabVIEW
LabVIEW
'I\'m a 2" string\n' "I'm a 2\" string\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...
#Java
Java
public class IntegerLiterals { public static void main(String[] args) { System.out.println( 727 == 0x2d7 && 727 == 01327 ); } }
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...
#JavaScript
JavaScript
if ( 727 == 0x2d7 && 727 == 01327 ) window.alert("true");
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 |...
#F.23
F#
let printLogic a b = printfn "a and b is %b" (a && b) printfn "a or b is %b" (a || b) printfn "Not a is %b" (not a) // The not-equals operator has the same effect as XOR on booleans. printfn "a exclusive-or b is %b" (a <> b)
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 |...
#Factor
Factor
: logical-operators ( a b -- ) { [ "xor is: " write xor . ] [ "and is: " write and . ] [ "or is: " write or . ] [ "not is: " write drop not . ] } 2cleave ;
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: ...
#Factor
Factor
"abc" "ABC" "123" [ [ write1 ] tri@ nl ] 3each
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...
#JavaScript
JavaScript
for (;;) { var a = Math.floor(Math.random() * 20); print(a); if (a == 10) break; a = Math.floor(Math.random() * 20); print(a); }
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 ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
a = "thisisatest"; b = "testing123testing"; LongestCommonSequence[a, b]
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...
#Fortran
Fortran
module LookAndSay implicit none   contains   subroutine look_and_say(in, out) character(len=*), intent(in) :: in character(len=*), intent(out) :: out   integer :: i, c character(len=1) :: x character(len=2) :: d   out = "" c = 1 x = in(1:1) do i = 2, len(trim(in)) if ( x =...
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...
#Swift
Swift
import Foundation   extension Array where Element: Comparable { @inlinable public func longestIncreasingSubsequence() -> [Element] { var startI = [Int](repeating: 0, count: count) var endI = [Int](repeating: 0, count: count + 1) var len = 0   for i in 0..<count { var lo = 1 var hi = len ...
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...
#Nim
Nim
for i in 1..10: if i mod 5 == 0: echo i continue stdout.write i, ", "
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...
#NS-HUBASIC
NS-HUBASIC
10 FOR I=1 TO 10 20 PRINT I; 30 IF I-I/5*5=0 THEN PRINT :GOTO 50"CONTINUE 40 PRINT ","; 50 NEXT
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...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func boolean: luhnTest (in string: cardNumber) is func result var boolean: luhnTest is FALSE; local var integer: index is 0; var integer: digit is 0; var boolean: isOdd is TRUE; var integer: oddSum is 0; var integer: evenSum is 0; begin for index range...
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...
#TI-83_BASIC
TI-83 BASIC
1024→I While I>0 Disp I I/2→I End  
http://rosettacode.org/wiki/Loops/While
Loops/While
Task Start an integer value at   1024. Loop while it is greater than zero. Print the value (with a newline) and divide it by two each time through the loop. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loops/For...
#TI-89_BASIC
TI-89 BASIC
Local i 1024 → i While i > 0 Disp i intDiv(i, 2) → i EndWhile
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...
#Salmon
Salmon
variable x := 0; do { ++x; x! } while (x % 6 != 0);
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#SAS
SAS
/* using DO UNTIL so that the loop executes at least once */ data _null_; n=0; do until(mod(n,6)=0); n+1; put n; end; run;
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. ...
#Klong
Klong
  :" x{p}:*y means repeat {p} x times starting at y "   5{x{.d(0c*);x}:*0;.p("");x+1}:*1   :" But you would not do it like this! " :" You would reshape 0c* to the desired length " :" in a function and then iterate that function " :" over a vector of numbers: "   {.p(x:^0c*)}'1+!5  
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...
#Pike
Pike
int main() { for(int i = 2; i <= 16; i=i+2) { write(i + "\n"); } }
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...
#Icon_and_Unicon
Icon and Unicon
procedure main() write(2^64*2^64) 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...
#Lasso
Lasso
'I\'m a 2" string\n' "I'm a 2\" string\n"
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...
#LaTeX
LaTeX
\documentclass{minimal} \begin{document} `a' is for ``apple" \end{document}
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...
#jq
jq
julia> 0b1011010111 == 0o1327 == 0x2d7 == 727 true
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...
#Julia
Julia
julia> 0b1011010111 == 0o1327 == 0x2d7 == 727 true
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 |...
#FALSE
FALSE
1 3=~["unequal, "]? 1 1= 1_=["true is -1, "]? 0~["false is 0, "]? 'm$'a>'z@>&["a < m < z"]?
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 |...
#Fantom
Fantom
  class Main { static Void doOps (Bool arg1, Bool arg2) { echo ("$arg1 and $arg2 = ${arg1.and(arg2)}") echo ("$arg1 or $arg2 = ${arg1.or(arg2)}") echo ("not $arg1 = ${arg1.not}") echo ("$arg1 xor $arg2 = ${arg1.xor(arg2)}") }   public static Void main () { [true,false].each |Bool arg1| ...
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: ...
#Fantom
Fantom
  class LoopMultiple { public static Void main () { List arr1 := ["a", "b", "c"] List arr2 := ["A", "B", "C"] List arr3 := [1, 2, 3] [arr1.size, arr2.size, arr3.size].min.times |Int i| { echo ("${arr1[i]}${arr2[i]}${arr3[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...
#jq
jq
take( rand(20); . != 10 )
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...
#Julia
Julia
  while true n = rand(0:19) @printf "%4d" n if n == 10 println() break end n = rand(0:19) @printf "%4d\n" n 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 ...
#Nim
Nim
proc lcs(x, y: string): string = if x == "" or y == "": return ""   if x[0] == y[0]: return x[0] & lcs(x[1..x.high], y[1..y.high])   let a = lcs(x, y[1..y.high]) let b = lcs(x[1..x.high], y) result = if a.len > b.len: a else: b   echo lcs("1234", "1224533324") echo lcs("thisisatest", "testing123testin...
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...
#FreeBASIC
FreeBASIC
  Dim As Integer n, j, k, k0, r Dim As String X(2) Dim As Integer i = 0 ' índice de cadena de entrada X(0) = "1"   Input "Indica cuantas repeticiones: ", r Print Chr(10) & "Secuencia:"   Print X(i) For n = 1 To r-1 j = 1 - i ' índice de cadena de salida X(j) = "" k = 1 While k <= Len(X(i)) k0 ...
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...
#Swym
Swym
Array.'lis' { 'stems' = Number.Array.mutableArray[ [] ]   forEach(this) 'value'-> { 'bestStem' = stems.where{==[] || .last < value}.max{.length}   stems.push( bestStem + [value] ) }   return stems.max{.length} }   [3,2,6,4,5,1].lis.trace [0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15].lis.trace
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...
#Objeck
Objeck
class Continue { function : Main(args : String[]) ~ Nil { for(i := 1; i <= 10; i += 1;) { if(i = 5) { "{$i}, "->PrintLine(); continue; }; "{$i}, "->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...
#OCaml
OCaml
# for i = 1 to 10 do try print_int i; if (i mod 5) = 0 then raise Exit; print_string ", " with Exit -> print_newline() done ;; 1, 2, 3, 4, 5 6, 7, 8, 9, 10 - : unit = ()
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...
#SenseTalk
SenseTalk
function LuhnCheck ccNum put length of ccNum into numDigits put the last character of ccNum into total put numDigits modulo 2 into parity repeat for each character of the first numDigits - 1 characters of ccNum put it into digit if (the counter - 1) modulo 2 equals parity multiply digit by 2 end if if d...
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...
#TorqueScript
TorqueScript
%num = 1024; while(%num > 0) { echo(%num);  %num = mFloor(%num / 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...
#Transact-SQL
Transact-SQL
  DECLARE @i INT = 1024; WHILE @i >0 BEGIN PRINT @i; SET @i = @i / 2; 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...
#Sather
Sather
class MAIN is main is val ::= 0; loop val := val + 1; #OUT + val + "\n"; while!(val % 6 /= 0) end; end; 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...
#Scala
Scala
{ var (x, l) = (0, List[Int]()) do { x += 1 l :+= x // A new copy of this list with List(x) appended. } while (x % 6 != 0) l }.foreach(println(_))  
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. ...
#Kotlin
Kotlin
fun main(args: Array<String>) { (1..5).forEach { (1..it).forEach { print('*') } 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...
#PILOT
PILOT
R  : Prints the odd numbers less than 10. C  :i = 1 *Loop T  :#i C  :i = i + 2 J ( i < 10 )  :*Loop 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...
#PL.2FI
PL/I
  declare (n, i) fixed binary;   get list (n); do i = 1 to n by 4; put skip list (i); 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...
#J
J
digits =: ,.&.": polymult =: +//.@(*/) buildDecimal=: 10x&#.   longmult=: buildDecimal@polymult&digits
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...
#Liberty_BASIC
Liberty BASIC
  'Liberty BASIC does not support escape characters within literal strings. print "Quotation mark:" print chr$(34) print   'Print literal string print "Hello, World." 'Print literal string displaying quotation marks. print chr$(34) + "Hello, World." + chr$(34)  
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...
#Lingo
Lingo
str = "Hello "&QUOTE&"world!"&QUOTE put str -- "Hello "world!""
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...
#Kotlin
Kotlin
// version 1.0.6   fun main(args: Array<String>) { val d = 255 // decimal integer literal val h = 0xff // hexadecimal integer literal val b = 0b11111111 // binary integer literal   val ld = 255L // decimal long integer literal (can't use l instea...
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...
#Lasso
Lasso
42 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 |...
#Forth
Forth
: .bool ( ? -- ) if ." true" else ." false" then ; : logic ( a b -- ) 0<> swap 0<> swap cr ." a = " over .bool ." b = " dup .bool cr ." a and b = " 2dup and .bool cr ." a or b = " over or .bool cr ." not a = " 0= .bool ;
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 |...
#Fortran
Fortran
SUBROUTINE PRNLOG(A, B) LOGICAL A, B PRINT *, 'a and b is ', A .AND. B PRINT *, 'a or b is ', A .OR. B PRINT *, 'not a is ', .NOT. A   C You did not ask, but the following logical operators are also standard C since ANSI FORTRAN 66 C ================================...
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: ...
#Fermat
Fermat
[a] := [('a','b','c')]; [b] := [('A','B','C')]; [c] := [(1,2,3)]; for i=1,3 do !!(a[i]:char,b[i]:char,c[i]:1) od; ;{note the :char and :1 suffixes. The former} ;{causes the element to be printed as a char} ;{instead of a numerical ASCII code, and the} ;{:1 causes the integer to take up exactly one} ;{space, ie. no lead...
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...
#Kotlin
Kotlin
import java.util.Random   fun main(args: Array<String>) { val rand = Random() while (true) { val a = rand.nextInt(20) println(a) if (a == 10) break println(rand.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 ...
#OCaml
OCaml
let longest xs ys = if List.length xs > List.length ys then xs else ys   let rec lcs a b = match a, b with [], _ | _, [] -> [] | x::xs, y::ys -> if x = y then x :: lcs xs ys else longest (lcs a ys) (lcs xs b)