Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Tcl...didnt get output

Status
Not open for further replies.

manchal

Newbie level 6
Newbie level 6
Joined
Feb 11, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,483
set xy [list a b c]
#set xy "{a b c {cd de {efg fgh}}} 1 2 {34 45 {567 678}}"
puts "$xy"
set l [ llength $xy ]
set j 0

puts "the index:"
#the proc of index
proc indx {x i {k ""}} {
set len [ llength $x ]
for {} {$i<$len} {incr i} {
set aa [lindex $x $i]
set b [llength $x]
if {($b == 1) && ($k == "")} {
return "[lindex $x $i ]-->$i $i"
} elseif {($b == 1)} {
return "[lindex $x $i ]-> $k- $i"
} else {
set s $i
if {$k != ""} {set s "$k-$s"}
return "[indx $aa $s]"
}
}
} ; #end of Proc

for {set m 0} {$m<$l} {incr m} {
set ak [indx $xy $j ] #updatng the valu evrytme proc is called.It updates the val only once.
#set j [lindex $ak 1]
puts "$j"
incr j
puts "$ak"
}



output:
a b c
the index:
0
a-->0 0
1

2
wanted as
0
a->0
1
b->1
2
c->2
 
Last edited:

Hai manchal,

The reason is the below for statement

for {} {$i<$len} {incr i} {

Its due to the value of i and len . First iteration the i value is 0 and len value is 1 so it enter into the loop . In second iteration ivalue is 1 and len value is also 1 so its not entering into it while recursive return statment. In third iteration ivalue is 2 and len value is 1 In this case also its not enterning. By analysing u will get it.

So while removing for we can easily achieve what u want.

change this statement return "[lindex $x $i ]-->$i $i" to statement return "[lindex $x 0 ]-->$i " to get the output which u want.
0
a->0
1
b->1
2
c->2

run the below code it will print the output which u need..

Code:
set xy [list a b c]
#set xy "{a b c {cd de {efg fgh}}} 1 2 {34 45 {567 678}}"
puts "$xy"
set l [ llength $xy ]
set j 0

puts "the index:"
#the proc of index
proc indx {x i {k ""}} {
set len [ llength $x ]
set aa [lindex $x $i]
set b [llength $x]
if {($b == 1) && ($k == "")} {
#return "[lindex $x $i ]-->$i $i"
return "[lindex $x 0 ]-->$i "
} elseif {($b == 1)} {
return "[lindex $x $i ]-> $k- $i"
} else {
set s $i
if {$k != ""} {set s "$k-$s"}
return "[indx $aa $s]"
}
} ; #end of Proc

for {set m 0} {$m<$l} {incr m} {
set ak [indx $xy $j ]
#set j [lindex $ak 1]
puts "$j"
incr j
puts "$ak"
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top