## Tcl9.0.3/Tk9.0.3 Documentation > Tcl Commands > lseq

### Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API

### NAME

lseq — リストとして返される数の並びの作成 Build a numeric sequence returned as a list

### 構文 SYNOPSIS

lseq start ?(..|to)? end ??by? step?
lseq start count count ??by? step?
lseq count ?by step?

### DESCRIPTION

lseq命令は､与えられたstartと endと step假引数を使って､広巾精度整数か倍精度整数の数値並びを創生する命令である｡ 操作引数の".." 又は "to"は､範囲を定める｡ "count"指示項目は､リスト内の要素の数値の個数を定める為に使われる｡ 本命令の短い形式の､一個の勘定値を伴う使用は､0からcount-1の範囲を作成する｡ The lseq command creates a sequence of numeric values, which may be either wide integers or doubles, using the given parameters start, end, and step. The operation argument ".." or "to" defines the range. The "count" option is used to define a count of the number of elements in the list. A short form use of the command, with a single count value, will create a range from 0 to count-1.

lseq命令は､昇順並びと降順並びの両方を生成できる｡ stepなしに開始 と 末尾の両方が提供されると､ もし､開始 <= 末尾であると､並びは昇順であり､ もし､開始 > 末尾であると､並びは降順である｡ もし､step値が含まれると､その符号が並びの方向と合致するべき(降順 → 負数 及び 昇順 → 正数)､さもないと空文字列が返される｡譬えば: The lseq command can produce both increasing and decreasing sequences. When both start and end are provided without a step value, then if start <= end, the sequence will be increasing and if start > end it will be decreasing. If a step vale is included, it's sign should agree with the direction of the sequence (descending → negative and ascending → positive), otherwise an empty list is returned. For example:

      % lseq 1 to 5    ;# 昇順 # increasing
      → 1 2 3 4 5

      % lseq 5 to 1    ;# 降順 # decreasing
      → 5 4 3 2 1

      % lseq 0 0.5 by 0.1  ;#倍精度 # doubles
      → 0.0 0.1 0.2 0.3 0.4 0.5

      % lseq 6 to 1 by 2   ;# 降順､step符号不適､空リスト # decreasing, step wrong sign, empty list

      % lseq 1 to 5 by 0   ;# step寸法全て0は空リスト生成 # all step sizes of 0 produce an empty list

数値引数のstartとendと stepと countは種々の表現であり得る｡ その表現が評価され数的な結果が使われる｡数として評価されない表現は不適正な引数不都合を生成する｡ The numeric arguments, start, end, step, and count, may also be a valid expression. The expression will be evaluated and the numeric result will be used. An expression that does not evaluate to a number will produce an invalid argument error.

startは最初の値を定め､そして､endは限度を定める､最後尾の値は必要ではない｡ lseqはcount要素のリストを作成し､そして､もし､countが供給されない場合は､次の様に計算する: Start defines the initial value and end defines the limit, not necessarily the last value. lseq produces a list with count elements, and if count is not supplied, it is computed as:

      count = int( (end - start + step) / step )

### 用例 EXAMPLES

    lseq 3
    → 0 1 2

    lseq 3 0
    → 3 2 1 0

    lseq 10 .. 1 by -2
    → 10 8 6 4 2

    set l [lseq 0 -5]
    → 0 -1 -2 -3 -4 -5

    foreach i [lseq [llength $l]] {
        puts l($i)=[lindex $l $i]
    }
    → l(0)=0
    → l(1)=-1
    → l(2)=-2
    → l(3)=-3
    → l(4)=-4
    → l(5)=-5

    foreach i [lseq {[llength $l]-1} 0] {
        puts l($i)=[lindex $l $i]
    }
    → l(5)=-5
    → l(4)=-4
    → l(3)=-3
    → l(2)=-2
    → l(1)=-1
    → l(0)=0

    set i 17
             → 17
    if {$i in [lseq 0 50]} { # equivalent to: (0 <= $i && $i <= 50)
        puts "Ok"
    } else {
        puts "outside :("
    }
    → Ok

    set sqrs [lmap i [lseq 1 10] { expr {$i*$i} }]
    → 1 4 9 16 25 36 49 64 81 100

### SEE ALSO

foreach, list, lappend, lassign, lindex, linsert, llength, lmap, lpop, lrange, lremove, lreplace, lreverse, lsearch, lset, lsort

### KEYWORDS

element, index, list
Copyright © 2022 Eric Taylor. All rights reserved.