0
각 입력 정수를 목록에 추가하고 나중에 정렬하려고하지만 반복하는 동안 각 정수를 목록에 추가하는 데 문제가 있습니다.TCL/TK 스크립트 반복에서 요소를 목록에 삽입
코드 :리스트의 마지막 요소를 추가하면
set l1 {1 2 3 4 5}
for {set i 0} {$i<[llength $l1]} {incr i} {
set data [gets stdin]
scan $data "%d" myint
if $myint<=0 {break} # stop if non positive number is found
set l1 {$myint} # supposed to add an input element into the list during iteration
}
puts $l1
대답은 다음과 같습니다. http://tcl.tk/man/tcl8.6/TclCmd/lappend.htm –
또한, [brace your expressions] (http://wiki.tcl.tk/10225) :' if {$ myint <= 0} {break}' –