Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

double loop 1

Status
Not open for further replies.

Eide

Technical User
Apr 22, 2010
7
NO
Hi all,

Because of getting tired of editing ini files I wanted to write a small prog helping me.

I have to make a list of several instruments and runs. I tried:

set maxtape 10
set maxsite 10

for { set i 1 } { $i <= $maxsite } { incr i } {
set j 0
for { set j 1 } { $j <= $maxtape } { incr j } {
puts " $i and $j "
} # for j
} # for i

I also tried a combination of while and for - also not working

set i 0
while { $i <= $maxsite } {
# puts "i is $i "
for { set j 1 } { $j <= $maxtape } { incr j } {
puts " $i and $j "
} # for j
set i [expr {$i + 1}]
}


I always get the following error:

Error in startup script: wrong # args: should be "for start test next command"

What am I doing wrong? Is it simply not possible to have a double loop?
If not how would I solve it? Thanks in advance.


Eide
 
Hi

In Tcl the comments can be placed only at the beginning of commands. So you have to terminate the [tt]for[/tt] before the [tt]#[/tt], either by placing a new-line or a semicolon ( ; ) between them :
Code:
[b]for[/b] [teal]{[/teal] [b]set[/b] i [purple]1[/purple] [teal]}[/teal] [teal]{[/teal] [navy]$i[/navy] [teal]<=[/teal] [navy]$maxsite[/navy] [teal]}[/teal] [teal]{[/teal] [b]incr[/b] i [teal]}[/teal] [teal]{[/teal]
    [b]set[/b] j [purple]0[/purple]
    [b]for[/b] [teal]{[/teal] [b]set[/b] j [purple]1[/purple] [teal]}[/teal] [teal]{[/teal] [navy]$j[/navy] [teal]<=[/teal] [navy]$maxtape[/navy] [teal]}[/teal] [teal]{[/teal] [b]incr[/b] j [teal]}[/teal] [teal]{[/teal]
        [b]puts[/b] [green][i]" $i and $j "[/i][/green]
    [teal]}[/teal][highlight][teal];[/teal][/highlight] [gray]# for j[/gray]
[teal]}[/teal][highlight][teal];[/teal][/highlight] [gray]# for i[/gray]


Feherke.
 
Thanks feherke for the quick reply - now I also understand the error message : )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top