new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
8
Task/Search-a-list/Tcl/search-a-list-1.tcl
Normal file
8
Task/Search-a-list/Tcl/search-a-list-1.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
|
||||
foreach needle {Bush Washington} {
|
||||
if {[set idx [lsearch -exact $haystack $needle]] == -1} {
|
||||
error "$needle does not appear in the haystack"
|
||||
} else {
|
||||
puts "$needle appears at index $idx in the haystack"
|
||||
}
|
||||
}
|
||||
9
Task/Search-a-list/Tcl/search-a-list-2.tcl
Normal file
9
Task/Search-a-list/Tcl/search-a-list-2.tcl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
set haystack {Zig Zag Wally Ronald Bush Krusty Charlie Bush Bozo}
|
||||
foreach needle {Bush Washington} {
|
||||
set indices [lsearch -all -exact $haystack $needle]
|
||||
if {[llength $indices] == 0} {
|
||||
error "$needle does not appear in the haystack"
|
||||
} else {
|
||||
puts "$needle appears first at index [lindex $indices 0] and last at [lindex $indices end]"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue