thing241
thing241

Reputation: 1

How to issue commands from inside a loop?

This is a very basic question.

I think of TCL as a command line generator. Its purpose is to generate strings for the tool’s command line interpreter. For example, the tcl commands:

set alpha “run”
$alpha
$alpha
$alpha

cause the “run” command to be sent to the tool three times – which makes sense. But:

set alpha “run”
for {set i 0} {$i<3} {incr i} $alpha

does not. So the question is: How do I send commands to the tool from inside a loop?

Upvotes: 0

Views: 65

Answers (2)

Sharad
Sharad

Reputation: 10592

Here's a possible way (with output):

% proc foo {count} {
    puts "count = $count"
}
% set alpha foo
foo
% for {set i 0} {$i<3} {incr i} {
    $alpha $i    
}
count = 0
count = 1
count = 2
% 

Upvotes: 0

Peter Lewerin
Peter Lewerin

Reputation: 13252

Your problem is likely to be with the "funny quotes" in the line

set alpha “run”

To Tcl, those quotes aren't syntactic markers, just text. Try

set alpha "run"

or, even better,

set alpha run

Upvotes: 1

Related Questions