<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.osgrid.org/index.php?action=history&amp;feed=atom&amp;title=LlGetListLength</id>
	<title>LlGetListLength - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.osgrid.org/index.php?action=history&amp;feed=atom&amp;title=LlGetListLength"/>
	<link rel="alternate" type="text/html" href="http://wiki.osgrid.org/index.php?title=LlGetListLength&amp;action=history"/>
	<updated>2026-10-25T11:50:19Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>http://wiki.osgrid.org/index.php?title=LlGetListLength&amp;diff=148&amp;oldid=prev</id>
		<title>Osgridadmin: Created page with &quot;==Function: integer llGetListLength( list src );== Returns an integer that is the number of elements in the list src. &lt;br&gt; • list 	src 			 &lt;br&gt; &lt;br&gt; Caveats &lt;br&gt; • The LSL...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.osgrid.org/index.php?title=LlGetListLength&amp;diff=148&amp;oldid=prev"/>
		<updated>2017-12-31T22:33:56Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Function: integer llGetListLength( list src );== Returns an integer that is the number of elements in the list src. &amp;lt;br&amp;gt; • list 	src 			 &amp;lt;br&amp;gt; &amp;lt;br&amp;gt; Caveats &amp;lt;br&amp;gt; • The LSL...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Function: integer llGetListLength( list src );==&lt;br /&gt;
Returns an integer that is the number of elements in the list src. &amp;lt;br&amp;gt;&lt;br /&gt;
• list 	src 			 &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Caveats &amp;lt;br&amp;gt;&lt;br /&gt;
• The LSL compiler will not optimize the condition, it will not hoisting this function out of the condition. Unless strictly necessary all work with strings, keys and lists should be manually hoisted and performed outside of the loop. See Best Practices for more details.  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Examples&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt;&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;lsl&amp;quot;&amp;gt;&lt;br /&gt;
//Basic usage&lt;br /&gt;
default&lt;br /&gt;
{&lt;br /&gt;
    state_entry()&lt;br /&gt;
    {&lt;br /&gt;
        list l = [&amp;quot;one&amp;quot;, &amp;quot;two&amp;quot;, &amp;quot;three&amp;quot;];&lt;br /&gt;
        integer i = llGetListLength(l);&lt;br /&gt;
        llOwnerSay(&amp;quot;there are &amp;quot; + (string)i + &amp;quot; entries in the list&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Notes&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Best Practices&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
When using list length to help you loop through a list, it is better to determine the length first, then start your loop:  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;lsl&amp;quot;&amp;gt;&lt;br /&gt;
integer i = 0;&lt;br /&gt;
integer length = llGetListLength(mylist);&lt;br /&gt;
for (; i &amp;lt; length; ++i) {&lt;br /&gt;
    llSay(0, llList2String(mylist, i));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
The following example is to illustrate what not to do, it calculates the length in the &amp;quot;for&amp;quot; loop and is inefficient because the length gets recalculated at each pass through the loop. This should only ever be done if the list is in fact changing (in length) with each iteration of the loop[1]. &amp;lt;br&amp;gt;&lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;lsl&amp;quot;&amp;gt;&lt;br /&gt;
integer i;&lt;br /&gt;
for (i = 0; i &amp;lt; llGetListLength(mylist); ++i) {&lt;br /&gt;
    llSay(0, llList2String(mylist, i));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Optimizations&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
A faster and lighter (in bytecode) way to determine the length of a list is to do a not-equals compare with a null list. This works because the list not-equals compare returns the difference between the lengths. &lt;br /&gt;
{|border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; cellspacing=&amp;quot;0&amp;quot;&lt;br /&gt;
|&amp;lt;source lang=&amp;quot;lsl&amp;quot;&amp;gt;&lt;br /&gt;
list in;&lt;br /&gt;
integer len_in = llGetListLength(in);&lt;br /&gt;
integer flen_in = (in != []);&lt;br /&gt;
//flen_in and len_in will be the same&lt;br /&gt;
 &lt;br /&gt;
integer neg_len_in = -llGetListLength(in);&lt;br /&gt;
integer fneg_len_in = ([] != in);&lt;br /&gt;
//fneg_len_in and neg_len_in will be the same&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
See Also &amp;lt;br&amp;gt;&lt;br /&gt;
Functions &amp;lt;br&amp;gt;&lt;br /&gt;
•  	[[llListStatistics]] 	– 	[[LIST_STAT_NUM_COUNT]] – Returns the number of integers and floats in the list 	 &amp;lt;br&amp;gt;&lt;br /&gt;
•  	[[llStringLength]] 	– 	Returns the number of characters in a string. 	 &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
Deep Notes &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Source&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;linden\indra\lscript\lscript_library\lscript_alloc.cpp&amp;#039; @ lsa_cmp_lists &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;linden\indra\lscript\lscript_execute\lscript_execute.cpp&amp;#039; @ list_list_operation &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Footnotes&amp;#039;&amp;#039;&amp;#039; &amp;lt;br&amp;gt;&lt;br /&gt;
1. ^ Recalculating the length is slow because the VM duplicates the entire list (including the values) when it is pushed on the stack (so it can be popped off the stack when the length is calculated).  &amp;lt;br&amp;gt; &amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>Osgridadmin</name></author>
	</entry>
</feed>