I need some help with my foreach loop logic:
I need to put a comma after each print statement except for the last statement in the loop
ex: blah,blah2,blahlast
The following code puts comma even after the last statement.
foreach row $regions {
set name [lindex $row 0]
set id [lindex $row 1]
puts "{'name':'$name', 'val':'$region_id'}"
puts ","
}
Maybe if i count the number of times its going to loop, I can probably check for an if condition to put comma unlti its the last iteration
The trick is to print the comma on all the iterations but the first one (that is, to reverse your logic):
would produce
Note that it seems you’re merely looking for the
joincommand.