Search Results

Search found 2 results on 1 pages for 'jerryk'.

Page 1/1 | 1 

  • Attempt to use a while loop for the 'next' arg of a for loop generates #arg error

    - by JerryK
    Am attempting to teach myself to program using Tcl. The task i've set myself to motivate my learning of Tcl is to solve the 8 queens problem. My approach to creating a program is to successively 'prototype' a solution. I have asked an earlier question related to the correctly laying out the nested for loops and received a helpful answer. To my dismay I find that the next development of my code creates the same interpreter error : "wrong # args" I have been careful to have an open brace at the end of the line preceding the while loop command. I've also tried to put the arguments of the whileloop in braces. This generates a different error. I have sincerely tried to understand the Tcl syntax man page - not too successfully - suggested by the answerer of my earlier question. Here is the code set allowd 1 set notallowd 0 for {set r1p 1} {$r1p <= 8} {incr r1p } { puts "1st row q placed at $r1p" ;# re-initialize r2 'free for q placemnt' array after every change of r1 q pos: for {set i 1 } {$i <= 8} {incr i} { set r2($i) $allowd } for { set r2($r1p) $notallowd ; set r2([expr $r1p-1]) $notallowd ; set r2([expr $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { ;# 'next' arg of r2 forloop will be a whileloop : while r2($r2p)== $notallowd incr r2p } { puts "2nd row q placed at $r2p" ;# end of 'commnd' arg of r2 forloop } } Where am I going wrong? EDIT : to provide clear reply @slebetman As stated in my text, I did brace the arguments of the whileloop (indeed that was how i first wrote the code) below is exactly the layout of the r2 forloop tried: for { set r2($r1p) $notallowd ; set r2([expr $r1p-1]) $notallowd ; set r2([expr $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { ;# 'next' arg of r2 forloop will be a whileloop : while { r2($r2p)== $notallowd } { incr r2p } } { puts "2nd row q placed at $r2p" ;# end of 'commnd' arg of r2 forloop } but this generates the fatal interpreter error : "unknown math function 'r2' while compiling while { r2($r2p .... "

    Read the article

  • Attempt to create nested for loops generating missing arguments error

    - by JerryK
    Am attempting to teach myself to program using Tcl. (I want to become more familiar with the language to understand someone else's code - SCID chess) The task i've set myself to motivate my learing of Tcl is to solve the 8 queens problem. My approach to creating a program is to sucessively 'prototype' a solution. So. I'm up to nesting a for loop holding the q pos on row 2 inside the for loop holding the q pos on row 1 Here is my code set allowd 1 set notallowd 0 for {set r1p 1} {$r1p <= 8} {incr r1p } { puts "1st row q placed at $r1p" ;# re-initialize r2 'free for q placemnt' array after every change of r1 q pos: for {set i 1 } {$i <= 8} {incr i} { set r2($i) $allowd } for { set r2($r1p) $notallowd ; set r2([eval $r1p-1]) $notallowd ; set r2([eval $r1p+1]) $notallowd ; set r2p 1} {$r2p <= 8} { incr r2p ;# end of 'next' arg of r2 forloop } ;# commnd arg of r2 forloop placed below: {puts "2nd row q placed at $r2p" } } My problem is that when i run the code the interpreter is aborting with the fatal error: "wrong #args should be for start test next command. I've gone over my code a few times and can't see that i've missed any of the for loop arguments.

    Read the article

1