Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

On my answer http://codegolf.stackexchange.com/a/107557/29325https://codegolf.stackexchange.com/a/107557/29325 I can demonstrate:

  1. Usually set j 0;while \$j<$n;{...;incr j} is shorter than the equivalent for {set j 0} {$j<$n} {incr j} {...}

  2. When the looping variable begins at 1, we can do the increment as part of the while test condition, avoiding to write before set i 1 unnecessarily: while {[incr i]<=$n} {...} instead of set i 1;while \$i<=$n;{...;incr i}

ATTENTION: One can only do 2. in the case of an outer loop! I could not apply it to my j variable as it needs to be reset to 1 in the outside of its own inner loop! And incr j would acquire the value that was set on the last step of the inner loop, instead of grabbing an undefined variable j to assume 0 and increment it to 1!

On my answer http://codegolf.stackexchange.com/a/107557/29325 I can demonstrate:

  1. Usually set j 0;while \$j<$n;{...;incr j} is shorter than the equivalent for {set j 0} {$j<$n} {incr j} {...}

  2. When the looping variable begins at 1, we can do the increment as part of the while test condition, avoiding to write before set i 1 unnecessarily: while {[incr i]<=$n} {...} instead of set i 1;while \$i<=$n;{...;incr i}

ATTENTION: One can only do 2. in the case of an outer loop! I could not apply it to my j variable as it needs to be reset to 1 in the outside of its own inner loop! And incr j would acquire the value that was set on the last step of the inner loop, instead of grabbing an undefined variable j to assume 0 and increment it to 1!

On my answer https://codegolf.stackexchange.com/a/107557/29325 I can demonstrate:

  1. Usually set j 0;while \$j<$n;{...;incr j} is shorter than the equivalent for {set j 0} {$j<$n} {incr j} {...}

  2. When the looping variable begins at 1, we can do the increment as part of the while test condition, avoiding to write before set i 1 unnecessarily: while {[incr i]<=$n} {...} instead of set i 1;while \$i<=$n;{...;incr i}

ATTENTION: One can only do 2. in the case of an outer loop! I could not apply it to my j variable as it needs to be reset to 1 in the outside of its own inner loop! And incr j would acquire the value that was set on the last step of the inner loop, instead of grabbing an undefined variable j to assume 0 and increment it to 1!

Source Link
sergiol
  • 3.5k
  • 1
  • 15
  • 31

On my answer http://codegolf.stackexchange.com/a/107557/29325 I can demonstrate:

  1. Usually set j 0;while \$j<$n;{...;incr j} is shorter than the equivalent for {set j 0} {$j<$n} {incr j} {...}

  2. When the looping variable begins at 1, we can do the increment as part of the while test condition, avoiding to write before set i 1 unnecessarily: while {[incr i]<=$n} {...} instead of set i 1;while \$i<=$n;{...;incr i}

ATTENTION: One can only do 2. in the case of an outer loop! I could not apply it to my j variable as it needs to be reset to 1 in the outside of its own inner loop! And incr j would acquire the value that was set on the last step of the inner loop, instead of grabbing an undefined variable j to assume 0 and increment it to 1!