renciso218 / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Unexpected behaviour from "count with" #126

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In Blockly Maze demo, level 10, I created block "Count with j from 1 to get 
direction"

When direction is zero, I expected it would execute zero times, but instead it 
executes twice.  The cause appears to be generated code attempting to guess 
whether I want it to count up or down:

      for (j = 1;
          (1 <= j_end) ? j <= j_end : j >= j_end;
          j += (1 <= j_end) ? 1 : -1) {

      }

This is clever but unexpected, and means that it is impossible to have a count 
with loop execute zero times.

Original issue reported on code.google.com by cpcal...@gmail.com on 19 Mar 2013 at 9:56

GoogleCodeExporter commented 8 years ago
I see your point.  But consider this program:
http://blockly-demo.appspot.com/static/apps/turtle/en.html#64w5jd
It would be equally unexpected for the second loop to do nothing.

Of course this is why real programming languages have a 'step by' parameter.  
Sigh, do we need all loops to step by (1)?

Original comment by neil.fra...@gmail.com on 20 Mar 2013 at 12:06

GoogleCodeExporter commented 8 years ago
I'm truly sorry there's no way to make everyone happy here.

Original comment by sper...@google.com on 8 Aug 2013 at 12:02