INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

problem with arrays

problem with arrays

(OP)
Hello,

I'm new with tcl programming language, and I need your help:
I want to create an array with some conditions. I have a variable len that says me how long the arry must be, and on the other hand, I have in another variable bete the number that I must have in all positions in the array. For example:

%set len 5
%set bete 123

So this is what i want to achieve in an array:
array = 123 123 123 123 123

I don't know if it is clear...

RE: problem with arrays

Short Example

CODE

set len 5
set bete 123

puts "Using Array:"
# create array
for {set i 1} {$i <=$len} {incr i} {
set arr($i)$bete
}

# print array
for {set i 1} {$i <=$len} {incr i} {
puts "arr($i) =$arr($i)" } puts "\nUsing List:" # create list set lst {} for {set i 1} {$i <= $len} {incr i} { lappend lst$bete
}

# print list
puts "\$lst = $lst$" set i 1 foreach el$lst {
puts "lst($i) =$el"
incr i
}
Output:

CODE

Using Array:
arr(1) = 123
arr(2) = 123
arr(3) = 123
arr(4) = 123
arr(5) = 123

Using List:
\$lst = [ 123 123 123 123 123 ]
lst(1) = 123
lst(2) = 123
lst(3) = 123
lst(4) = 123
lst(5) = 123

RE: problem with arrays

(OP)
Thanks mikron, it works!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!