Array length: Difference between revisions
Added EchoLisp |
Walterpachl (talk | contribs) add REXX |
||
Line 36: | Line 36: | ||
2 |
2 |
||
>>> </lang> |
>>> </lang> |
||
=={{header|REXX}}== |
|||
<lang rexx>/* REXX ------------------------------------------------ |
|||
* The compond variable a. implements an array |
|||
* By convention, a.0 contains the number of elements |
|||
*---------------------------------------------------*/ |
|||
a.=0 /* initialize the "array" */ |
|||
call store 'apple' |
|||
Call store 'orange' |
|||
Say 'There are' a.0 'elements in the array:' |
|||
Do i=1 To a.0 |
|||
Say 'Element' i':' a.i |
|||
End |
|||
Exit |
|||
store: Procedure Expose a. |
|||
z=a.0+1 |
|||
a.z=arg(1) |
|||
a.0=z |
|||
Return</lang> |
|||
{{out}} |
|||
<pre>E:\>There are 2 elements in the array: |
|||
Element 1: apple |
|||
Element 2: orange</pre> |
|||
=={{header|SQL}}== |
=={{header|SQL}}== |
Revision as of 18:08, 27 September 2015
Determine the amount of elements in an array.
As an example use an array holding the strings 'apple' and 'orange'.
- See also
ALGOL 68
<lang algol68># UPB returns the upper bound of an array, LWB the lower bound # []STRING fruits = ( "apple", "orange" ); print( ( ( UPB fruits - LWB fruits ) + 1, newline ) ) # prints 2 #</lang>
EchoLisp
<lang scheme> (length '("apple" "orange")) ;; list
→ 2
(vector-length #("apple" "orange")) ;; vector
→ 2
</lang>
Haskell
<lang Haskell>-- Char -> Int length ["apple", "orange"]</lang>
JavaScript
<lang javascript>console.log(['apple', 'orange'].length);</lang>
PHP
<lang php>print count(['apple', 'orange']); // Returns 2</lang>
Python
<lang python>>>> print(len(['apple', 'orange'])) 2 >>> </lang>
REXX
<lang rexx>/* REXX ------------------------------------------------
- The compond variable a. implements an array
- By convention, a.0 contains the number of elements
- ---------------------------------------------------*/
a.=0 /* initialize the "array" */ call store 'apple' Call store 'orange' Say 'There are' a.0 'elements in the array:' Do i=1 To a.0
Say 'Element' i':' a.i End
Exit store: Procedure Expose a. z=a.0+1 a.z=arg(1) a.0=z Return</lang>
- Output:
E:\>There are 2 elements in the array: Element 1: apple Element 2: orange
SQL
<lang sql>SELECT COUNT() FROM (VALUES ('apple'),('orange'));</lang>