Version 5 of llength

Updated 2004-08-20 13:20:40

The man page for llength is http://purl.org/tcl/home/man/tcl8.4/TclCmd/llength.htm

This command returns the number of elements in the list. If the string is not a well-formed list, an error will be thrown.


caspian: Make sure to give llength the list, not just the name variable where the list is stored.

# This is the right way to do it.

 set mylist [list "a" "b" "c"]

# In fact, this is equivalent to the above, and less redundant:

 set mylist {a b c}

 llength $mylist

 # This is the WRONG way to do it.
 # This won't return an error, but it will always return "1",
 # no matter how long or short your list is.
 set mylist [list "a" "b" "c"]
 llength mylist

See also list, lappend, lindex, linsert, lrange, lreplace, lsearch, lsort .


Tcl syntax help - Arts and crafts of Tcl-Tk programming - Category Command