Array length: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added an Algol 68 Sample)
Line 5: Line 5:
;See also:
;See also:
* [[String length]]
* [[String length]]

=={{header|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>


=={{header|Haskell}}==
=={{header|Haskell}}==

Revision as of 14:53, 27 September 2015

Array length is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

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>

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>

SQL

<lang sql>SELECT COUNT() FROM (VALUES ('apple'),('orange'));</lang>