INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Jobs

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...

Thanks in advance

looking forward to your help

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!! smile

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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close