Jump to content

Assigning Values to an Array: Difference between revisions

m
→‎{{header|Tcl}}: formatting tweak
(omits)
m (→‎{{header|Tcl}}: formatting tweak)
Line 542:
 
=={{header|Tcl}}==
<lang tcl>proc setIfExist {theVariable value} {
upvar 1 $theVariable variable
if {[info exists theVariable]} {
set theVariable $value
} else {
error "$theVariable doesn't exist"
}
}</lang>
}
Note that <tt>setIfExist</tt> is general purpose and works on regular variables as well as arrays:
<lang tcl>setIfExist foo(bar) 10 ;# error if foo(bar) doesn't exist
setIfExist x 10 ;# error if x doesn't exist</lang>
 
=={{header|Toka}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.