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/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...
#NS-HUBASIC
NS-HUBASIC
10 I=RND(20) 20 PRINT I 30 IF I=10 THEN STOP 40 PRINT RND(20) 50 GOTO 10
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 ...
#REXX
REXX
/*REXX program tests the LCS (Longest Common Subsequence) subroutine. */ parse arg aaa bbb . /*obtain optional arguments from the CL*/ say 'string A =' aaa /*echo the string A to the screen. */ say 'string B =' bbb ...
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...
#Lasso
Lasso
define rle(str::string)::string => { local(orig = #str->values->asCopy,newi=array, newc=array, compiled=string) while(#orig->size) => { if(not #newi->size) => { #newi->insert(1) #newc->insert(#orig->first) #orig->remove(1) else if(#orig->first == #newc->last) => { #newi->get(#newi->size) += 1 e...
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...
#Ring
Ring
  for i = 1 TO 10 see i if i % 5 = 0 see nl loop ok see ", " next  
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...
#Ruby
Ruby
for i in 1..10 do print i if i % 5 == 0 then puts next end print ', ' end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#UNIX_Shell
UNIX Shell
function luhn { typeset n p s t=('0123456789' '0516273849') while ((-n<${#1})); do p="${t[n--%2]%${1:n:1}*}" ((s+=${#p})) done ((s%10)) }   for c in 49927398716 49927398717 1234567812345678 1234567812345670; do if luhn $c; then echo $c is invalid else echo $c is valid fi don...
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...
#XPL0
XPL0
code CrLf=9, IntOut=11; int V; [V:= 0; repeat V:= V+1; IntOut(0, V); CrLf(0); until rem(V/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...
#Yorick
Yorick
val = 0; do { val++; write, val; } while(val % 6 != 0);
http://rosettacode.org/wiki/Loops/For
Loops/For
“For”   loops are used to make some block of code be iterated a number of times, setting a variable or parameter to a monotonically increasing integer value for each execution of the block of code. Common extensions of this allow other counting patterns or iterating over abstract structures other than the integers. ...
#make
make
all: line-5   ILIST != jot 5 .for I in $(ILIST)   line-$(I): asterisk-$(I)-$(I) @echo   JLIST != jot $(I) . for J in $(JLIST)   . if "$(J)" == "1" . if "$(I)" == "1" asterisk-1-1: . else IM != expr $(I) - 1 asterisk-$(I)-1: line-$(IM) . endif . else JM != expr $(J) - 1 asterisk-$(I)-$(J): asterisk-$(I)-$(JM) ....
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...
#Spin
Spin
con _clkmode = xtal1 + pll16x _clkfreq = 80_000_000   obj ser : "FullDuplexSerial.spin"   pub main | n ser.start(31, 30, 0, 115200)   repeat n from 0 to 19 step 3 ser.dec(n) ser.tx(32)   waitcnt(_clkfreq + cnt) ser.stop cogstop(0)
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...
#SPL
SPL
> n, 1..10,2 #.output(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...
#PARI.2FGP
PARI/GP
long(a,b)={ a=eval(Vec(a)); b=eval(Vec(b)); my(c=vector(#a+#b),carry=0); for(i=1,#a, for(j=1,#b, c[i+j]+=a[i]*b[j] ) ); forstep(i=#c,1,-1, c[i] += carry; carry = c[i] \ 10; c[i] = c[i] % 10 ); for(i=1,#c, if(c[i], return(concat(apply(s->Str(s),vector(#c+1-i,j,c[i+j-1]))))) ...
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...
#Plain_TeX
Plain TeX
`a' is for ``apple" \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...
#PL.2FI
PL/I
  12345 'b4'xn /* a hexadecimal literal integer. */ 'ffff_ffff'xn /* a longer hexadecimal hexadecimal integer. */ 1101b /* a binary integer, of value decimal 13. */  
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...
#PostScript
PostScript
123  % 123 8#1777  % 1023 16#FFFE  % 65534 2#11011  % 27 5#44  % 24
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 |...
#LIL
LIL
# Logical operations, in LIL set first [expr 1 == 1] set second [expr 1 == 0]   func and-or-not {a b} { print a $a b $b print "a AND b" [expr $a && $b] print "a OR b " [expr $a || $b] print "NOT a " [expr !$a] }   and-or-not $first $second
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 |...
#LiveCode
LiveCode
function boolOps p1, p2 local boolOpsResult put p1 && "AND" && p2 && "=" && merge("[[p1 and p2]]") & cr after boolOpsResult put p1 && "OR" && p2 && "=" && merge("[[p1 or p2]]") & cr after boolOpsResult put "NOT" && p1 && "=" && merge("[[not p1]]") & cr after boolOpsResult return boolOpsResult end b...
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: ...
#Icon_and_Unicon
Icon and Unicon
procedure main() a := create !["a","b","c"] b := create !["A","B","C"] c := create !["1","2","3"] while write(@a,@b,@c) 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...
#Oberon-2
Oberon-2
  MODULE LoopBreak; IMPORT RandomNumbers, Out;   PROCEDURE Do(); VAR rn: LONGINT; BEGIN LOOP rn := RandomNumbers.RND(20); Out.LongInt(rn,0);Out.Ln; IF rn = 10 THEN EXIT END; rn := RandomNumbers.RND(20); Out.LongInt(rn,0);Out.Ln END END Do;   BEGIN Do END LoopBreak.  
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...
#Objeck
Objeck
  while(true) { a := (Float->Random() * 20.0)->As(Int); a->PrintLine(); if(a = 10) { break; }; a := (Float->Random() * 20.0)->As(Int); a->PrintLine(); }  
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 ...
#Ring
Ring
  see longest("1267834", "1224533324") + nl   func longest a, b if a = "" or b = "" return "" ok if right(a, 1) = right(b, 1) lcs = longest(left(a, len(a) - 1), left(b, len(b) - 1)) + right(a, 1) return lcs else x1 = longest(a, left(b, len(b) - 1)) x2 = longest(left(a, l...
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...
#LiveCode
LiveCode
function lookAndSay S put 0 into C put char 1 of S into lastChar repeat with i = 2 to length(S) add 1 to C if char i of S is lastChar then next repeat put C & lastChar after R put 0 into C put char i of S into lastChar end repeat return R & C + 1 & lastChar end lookAndSay   ...
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...
#Rust
Rust
fn main() { for i in 1..=10 { print!("{}", i); if i % 5 == 0 { println!(); 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...
#Salmon
Salmon
iterate (x; [1...10]) { print(x); if (x % 5 == 0) { print("\n"); continue; }; 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...
#Ursala
Ursala
#import std #import nat   luhn = %nP; %np*hxiNCNCS; not remainder\10+ //sum:-0@DrlrHK32 ~&iK27K28TK25 iota10
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...
#zkl
zkl
val := 0; do { val+=1; val.print(" "); } while(val % 6 != 0);
http://rosettacode.org/wiki/Loops/Do-while
Loops/Do-while
Start with a value at 0. Loop while value mod 6 is not equal to 0. Each time through the loop, add 1 to the value then print it. The loop must execute at least once. Related tasks   Loop over multiple arrays simultaneously   Loops/Break   Loops/Continue   Loops/Do-while   Loops/Downward for   Loops/For   Loo...
#Zig
Zig
const std = @import("std");   pub fn main() !void { var a: u8 = 0; // no do-while in syntax, trust the optimizer to do // correct Loop inversion https://en.wikipedia.org/wiki/Loop_inversion // If the variable `alive` is independent to other variables and not in // diverging control flow, then the op...
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. ...
#Maple
Maple
> for i to 5 do to i do printf( "*" ) end; printf( "\n" ) 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...
#SSEM
SSEM
10101000000000100000000000000000 0. -21 to c 00101000000001100000000000000000 1. c to 20 00101000000000100000000000000000 2. -20 to c 01101000000000010000000000000000 3. Sub. 22 10101000000001100000000000000000 4. c to 21 00000000000000110000000000000000 5. Test 01001000000001000000000000000000 6. Add 18 ...
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...
#Stata
Stata
forvalues i=1(2)10 { display "`i'" }   1 3 5 7 9
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...
#Pascal
Pascal
  Program TwoUp; Uses DOS, crt; {Concocted by R.N.McLean (whom God preserve), Victoria university, NZ.} Procedure Croak(gasp: string); Begin Writeln; Write(Gasp); HALT; End;   const BigBase = 10; {The base of big arithmetic.} const BigEnuff = 333; {The most storage possible is 65532 bytes with Turbo P...
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...
#Pop11
Pop11
'a'  ;;; string consisting of single character
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...
#PowerShell
PowerShell
'This is an "atom" and not a string.'
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...
#PowerShell
PowerShell
727 # base 10 0x2d7 # base 16
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...
#PureBasic
PureBasic
x = 15 ;15 in base 10 x = %1111 ;15 in base 2 x = $f ;15 in base 16
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 |...
#LLVM
LLVM
; This is not strictly LLVM, as it uses the C library function "printf". ; LLVM does not provide a way to print values, so the alternative would be ; to just load the string into memory, and that would be boring.   ; Additional comments have been inserted, as well as changes made from the output produced by clang such ...
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: ...
#J
J
,.&:(":"0@>)/ 'abc' ; 'ABC' ; 1 2 3 aA1 bB2 cC3
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...
#OCaml
OCaml
# Random.self_init();; - : unit = ()   # while true do let a = Random.int 20 in print_int a; print_newline(); if a = 10 then raise Exit; let b = Random.int 20 in print_int b; print_newline() done;; 15 18 2 13 10 Exception: Pervasives.Exit.
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 ...
#Ruby
Ruby
=begin irb(main):001:0> lcs('thisisatest', 'testing123testing') => "tsitest" =end def lcs(xstr, ystr) return "" if xstr.empty? || ystr.empty?   x, xs, y, ys = xstr[0..0], xstr[1..-1], ystr[0..0], ystr[1..-1] if x == y x + lcs(xs, ys) else [lcs(xstr, ys), lcs(xs, ystr)].max_by {|x| x.size} end 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...
#Logo
Logo
to look.and.say.loop :in :run :c :out if empty? :in [output (word :out :run :c)] if equal? first :in :c [output look.and.say.loop bf :in :run+1 :c :out] output look.and.say.loop bf :in 1 first :in (word :out :run :c) end to look.and.say :in if empty? :in [output :in] output look.and.say.loop bf :in 1 first :i...
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...
#Lua
Lua
--returns an iterator over the first n copies of the look-and-say sequence function lookandsayseq(n) local t = {1} return function() local ret = {} for i, v in ipairs(t) do if t[i-1] and v == t[i-1] then ret[#ret - 1] = ret[#ret - 1] + 1 else ret[#ret + 1] = 1 ret[#ret + ...
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...
#Sather
Sather
class MAIN is main is i:INT; loop i := 1.upto!(10); #OUT + i; if i%5 = 0 then #OUT + "\n"; else #OUT + ", "; end; end; 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...
#Scala
Scala
for (i <- 1 to 10) { print(i) if (i % 5 == 0) println() else 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...
#VBA
VBA
  Option Explicit   Sub Main() Debug.Print "Number 49927398716 is "; Luhn("49927398716") Debug.Print "Number 49927398717 is "; Luhn("49927398717") Debug.Print "Number 1234567812345678 is "; Luhn("1234567812345678") Debug.Print "Number 1234567812345670 is "; Luhn("1234567812345670") End Sub Private Function Luhn...
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. ...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
n=5; For[i=1,i<=5,i++, string=""; For[j=1,j<=i,j++,string=string<>"*"]; Print[string] ]
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...
#Swift
Swift
for i in stride(from: 1, to: 10, by: 2) { print(i) }
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...
#Tailspin
Tailspin
  1..9:3 -> !OUT::write  
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...
#Perl
Perl
#!/usr/bin/perl -w use strict;   # This should probably be done in a loop rather than be recursive. sub add_with_carry { my $resultref = shift; my $addend = shift; my $addendpos = shift;   push @$resultref, (0) while (scalar @$resultref < $addendpos + 1); my $addend_result = $addend + $resultref->[$addendpos]...
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...
#Prolog
Prolog
'This is an "atom" and not a string.'
http://rosettacode.org/wiki/Literals/String
Literals/String
Task Show literal specification of characters and strings. If supported, show how the following work:   verbatim strings   (quotes where escape sequences are quoted literally)   here-strings   Also, discuss which quotes expand variables. Related tasks   Special characters   Here document Other tasks r...
#PureBasic
PureBasic
; Characters (*.c), can be ASCII or UNICODE depending on compiler setting Define.c AChar='A' ; defines as *.a it will be ASCII and *.u is always UNICODE Define.a A='b' Define.u U='水'   ; Strings is defined as **.s or ending with '$' Define.s AStrion ="String #1" Define BStrion.s ="String #2" Define CStr...
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...
#Python
Python
>>> # Bin(leading 0b or 0B), Oct(leading 0o or 0O), Dec, Hex(leading 0x or 0X), in order: >>> 0b1011010111 == 0o1327 == 727 == 0x2d7 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...
#Quackery
Quackery
[ 2 base put ] now!   ( The Quackery compiler now expects numeric literals to be in binary. )   [ base release ] now!   ( The Quackery compiler now expects numeric literals to be in whichever base they were previously. The default base is decimal. )
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 |...
#Logo
Logo
to logic :a :b (print [a AND b =] and :a :b) (print [a OR b =] or :a :b) (print [NOT a =] not :a) 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 |...
#Lua
Lua
  function logic(a,b) return a and b, a or b, not a end  
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: ...
#Java
Java
String[][] list1 = {{"a","b","c"}, {"A", "B", "C"}, {"1", "2", "3"}}; for (int i = 0; i < list1.length; i++) { for (String[] lista : list1) { System.out.print(lista[i]); } System.out.println(); }
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...
#Octave
Octave
while(1) a = floor(unifrnd(0,20, 1)); disp(a) if ( a == 10 ) break endif b = floor(unifrnd(0,20, 1)); disp(b) endwhile
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 ...
#Run_BASIC
Run BASIC
a$ = "aebdaef" b$ = "cacbac" print lcs$(a$,b$) end   FUNCTION lcs$(a$, b$) IF a$ = "" OR b$ = "" THEN lcs$ = "" goto [ext] end if   IF RIGHT$(a$, 1) = RIGHT$(b$, 1) THEN lcs$ = lcs$(LEFT$(a$, LEN(a$) - 1), LEFT$(b$, LEN(b$) - 1)) + RIGHT$(a$, 1) goto [ext] ELSE x1$ = lcs$(a$, LEFT$(b$, LEN(b$) - 1)) x2$ = ...
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...
#M4
M4
divert(-1) define(`for', `ifelse($#,0,``$0'', `ifelse(eval($2<=$3),1, `pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')   define(`las', `patsubst(`$1',`\(\(.\)\2*\)',`len(\1)`'\2')')     define(`v',1) divert for(`x',1,10, `v define(`v',las(v))')dnl v
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...
#Scheme
Scheme
(define (loop i) (if (> i 10) 'done (begin (display i) (cond ((zero? (modulo i 5)) (newline) (loop (+ 1 i))) (else (display ", ") (loop (+ 1 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...
#Scilab
Scilab
for i=1:10 printf("%2d ",i) if modulo(i,5)~=0 then printf(", ") continue end printf("\n") end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#VBScript
VBScript
Function Luhn_Test(cc) cc = RevString(cc) s1 = 0 s2 = 0 For i = 1 To Len(cc) If i Mod 2 > 0 Then s1 = s1 + CInt(Mid(cc,i,1)) Else tmp = CInt(Mid(cc,i,1))*2 If tmp < 10 Then s2 = s2 + tmp Else s2 = s2 + CInt(Right(CStr(tmp),1)) + 1 End If End If Next If Right(CStr(s1 + s2),1) = "0" T...
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. ...
#MATLAB_.2F_Octave
MATLAB / Octave
for i = (1:5) output = []; for j = (1:i) output = [output '*']; end disp(output); 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...
#Tcl
Tcl
for {set i 2} {$i <= 8} {incr i 2} { puts -nonewline "$i, " } puts "enough with the cheering already!"
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...
#Phix
Phix
constant base = 1_000_000_000 function bcd9_mult(sequence a, sequence b) sequence c = repeat(0,length(a)+length(b)) for i=1 to length(a) do integer j = i+length(b)-1 c[i..j] = sq_add(c[i..j],sq_mul(a[i],b)) end for for i=1 to length(c) do atom ci = c[i] if ci>base t...
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...
#Python
Python
'c' == "c" # character 'text' == "text" ' " ' " ' " '\x20' == ' ' u'unicode string' u'\u05d0' # unicode literal
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...
#Quackery
Quackery
/O> char X emit ... char Y emit ... char Z emit cr ... $ "This is a 'string'." echo$ cr ... $ 'This is a "string" too.' echo$ cr ... $ ~This is one with "quotes" and 'apostrophes'.~ echo$ cr ... $ \Any non-whitespace character can be the delimiter.\ echo$ cr ... XYZ This is a 'string'. This is a "string" too. This is ...
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...
#R
R
0x2d7==727 # TRUE identical(0x2d7, 727) # TRUE is.numeric(727) # TRUE is.integer(727) # FALSE is.integer(727L) # TRUE is.numeric(0x2d7) # TRUE is.integer(0x2d7) # FALSE is.integer(0x2d7L) # 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...
#Racket
Racket
  #lang racket #b1011010111 #o1327 #d727 #x2d7  
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 |...
#M2000_Interpreter
M2000 Interpreter
  Module CheckIt { Def Boolean A, B Document Rep$ A=True B=False k=(A, B) And=Lambda (a as Boolean, b as Boolean)-> a and b Or=Lambda (a as Boolean, b as Boolean)-> a or b Xor=Lambda (a as Boolean, b as Boolean)-> a xor b Not=Lambda (a)->Not a func=((And, "And...
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 |...
#M4
M4
define(`logical', `and($1,$2)=eval($1&&$2) or($1,$2)=eval($1||$2) not($1)=eval(!$1)') logical(1,0)
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: ...
#JavaScript
JavaScript
var a = ["a","b","c"], b = ["A","B","C"], c = [1,2,3], output = "", i; for (i = 0; i < a.length; i += 1) { output += a[i] + b[i] + c[i] + "\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...
#Oforth
Oforth
while(true) [ 19 rand dup print ":" print 10 == ifTrue: [ break ] 19 rand print " " print ]
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...
#Ol
Ol
  (import (otus random!))   (call/cc (lambda (break) (let loop () (if (= (rand! 20) 10) (break #t)) (print (rand! 20)) (loop))))  
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 ...
#Rust
Rust
  use std::cmp;   fn lcs(string1: String, string2: String) -> (usize, String){ let total_rows = string1.len() + 1; let total_columns = string2.len() + 1; // rust doesn't allow accessing string by index let string1_chars = string1.as_bytes(); let string2_chars = string2.as_bytes();   let mut tabl...
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...
#Maple
Maple
generate_seq := proc(s) local times, output, i; times := 1; output := ""; for i from 2 to StringTools:-Length(s) do if (s[i] <> s[i-1]) then output := cat(output, times, s[i-1]); times := 1; # re-assign else times ++; end if; end do; cat(output, times, s[i - 1]); end proc:   Look_and_Say :=proc(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...
#Sidef
Sidef
for i in (1..10) { print i if (i %% 5) { print "\n" next } 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...
#Simula
Simula
! Loops/Continue - simula67 - 07/03/2017; begin integer i; for i:=1 step 1 until 10 do begin outint(i,5); if mod(i,5)=0 then begin outimage; goto loop end; outtext(", "); loop: end end
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
Luhn test of credit card numbers
The Luhn test is used by some credit card companies to distinguish valid credit card numbers from what could be a random selection of digits. Those companies using credit card numbers that can be validated by the Luhn test have numbers that pass the following test: Reverse the order of the digits in the number. Tak...
#Visual_Basic
Visual Basic
Public Function LuhnCheckPassed(ByVal dgts As String) As Boolean Dim i As Long, s As Long, s1 As Long dgts = VBA.StrReverse(dgts) For i = 1 To Len(dgts) Step 2 s = s + CInt(Mid$(dgts, i, 1)) Next i For i = 2 To Len(dgts) Step 2 s1 = 2 * (CInt(Mid$(dgts, i, 1))) If s1 >= 10 Then ...
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. ...
#Maxima
Maxima
for i thru 5 do ( s: "", thru i do s: sconcat(s, "*"), print(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...
#TorqueScript
TorqueScript
for(%i = 0; %i < 201; %i += 2) { echo(%i); }
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...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT LOOP i=2,9,2 PRINT i ENDLOOP  
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...
#PHP
PHP
<?php function longMult($a, $b) { $as = (string) $a; $bs = (string) $b; for($pi = 0, $ai = strlen($as) - 1; $ai >= 0; $pi++, $ai--) { for($p = 0; $p < $pi; $p++) { $regi[$ai][] = 0; } for($bi = strlen($bs) - 1; $bi >= 0; $bi--) { $regi[$ai][] = $as[$ai] ...
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...
#R
R
str1 <- "the quick brown fox, etc." str2 <- 'the quick brown fox, etc.' identical(str1, str2) #returns TRUE
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...
#Racket
Racket
  #\a #\space #\return  
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...
#Raku
Raku
say 255; say 0d255; say 0xff; say 0o377; say 0b1111_1111;   say :10<255>; say :16<ff>; say :8<377>; say :2<1111_1111>; say :3<100110>; say :4<3333>; say :12<193>; say :36<73>;
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...
#REBOL
REBOL
1
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 |...
#Maple
Maple
  f:=proc(a,b) a and b, a or b, not a; end proc:   f(true,true); f(true,false); f(false,true); f(false,false);  
http://rosettacode.org/wiki/Logical_operations
Logical operations
Basic Data Operation This is a basic data operation. It represents a fundamental action on a basic data type. You may see other such operations in the Basic Data Operations category, or: Integer Operations Arithmetic | Comparison Boolean Operations Bitwise | Logical String Operations Concatenation | Interpolation |...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
And[a,b,...] Or[a,b,...] Not[a]
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: ...
#jq
jq
# zip/0 emits [] if input is [].   def zip: . as $in | [range(0; $in[0]|length) as $i | $in | map( .[$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...
#ooRexx
ooRexx
/*REXX **************************************************************** * Three Ways to leave a Loop * ooRexx added the possibility to leave an outer loop * without using a control variable * 12.05.2013 Walter Pachl **********************************************************************/ do i1=1 To 2 ...
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 ...
#Scala
Scala
def lcsLazy[T](u: IndexedSeq[T], v: IndexedSeq[T]): IndexedSeq[T] = { def su = subsets(u).to(LazyList) def sv = subsets(v).to(LazyList) su.intersect(sv).headOption match{ case Some(sub) => sub case None => IndexedSeq[T]() } }   def subsets[T](u: IndexedSeq[T]): Iterator[IndexedSeq[T]] ...
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...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
LookAndSay[n_Integer?Positive]:= Reverse @@@ Tally /@ Split @ IntegerDigits @ n // Flatten // FromDigits
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...
#Smalltalk
Smalltalk
  1 to: 10 do: [ :i | [ :continue | i % 5 = 0 ifTrue: [ Transcript show: i; cr. continue value ]. Transcript show: i; show: ', '. ] valueWithExit. ]  
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...
#Spin
Spin
con _clkmode = xtal1 + pll16x _clkfreq = 80_000_000   obj ser : "FullDuplexSerial.spin"   pub main | i ser.start(31, 30, 0, 115200)   repeat i from 1 to 10 ser.dec(i) if i // 5 ser.str(string(", ")) next ser.str(string(13,10))   waitcnt(_clkfreq + cnt) ser.stop cogstop(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...
#Visual_Basic_.NET
Visual Basic .NET
  Imports System.Linq Function ValidLuhn(value As String) Return value.Select(Function(c, i) (AscW(c) - 48) << ((value.Length - i - 1) And 1)).Sum(Function(n) If(n > 9, n - 9, n)) Mod 10 = 0 End Function Sub Main() Console.WriteLine(ValidLuhn("49927398716")) Console.WriteLine(Val...
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. ...
#MAXScript
MAXScript
for i in 1 to 5 do ( line = "" for j in 1 to i do ( line += "*" ) format "%\n" line )
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...
#UNIX_Shell
UNIX Shell
x=2 while test $x -le 8; do echo $x x=`expr $x + 2` || exit $? done
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...
#Ursa
Ursa
decl int i for (set i 2) (< i 9) (set i (int (+ i 2))) out i ", " console end for out "who do we appreciate?" endl console
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...
#PicoLisp
PicoLisp
  (de multi (A B) (setq A (format A) B (reverse (chop B))) (let Result 0 (for (I . X) B (setq Result (+ Result (* (format X) A (** 10 (dec 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...
#Raku
Raku
Short Long Meaning ===== ==== ======= :x  :exec Execute as command and return results :w  :words Split result on words (no quote protection) :ww  :quotewords Split result on words (with quote protection) :v  :val Evaluate...