Merge pull request #43 from stevoleeto/whileLoop

add while loop
zeedee
gasolin 7 years ago
commit cfc575cd30
  1. 1
      blockly/apps/blocklyduino/index.html
  2. 2
      blockly/blocks/loops.js
  3. 17
      blockly/generators/arduino/control.js

@ -339,6 +339,7 @@ function init() {
</block>
</value>
</block>
<block type="controls_whileUntil"></block>
</category>
<category name="Math">
<block type="math_number"></block>

@ -26,6 +26,8 @@
goog.provide('Blockly.Blocks.loops');
goog.provide('Blockly.Blocks.controls');
goog.require('Blockly.Blocks');

@ -75,3 +75,20 @@ Blockly.Arduino.controls_for = function() {
}
return code;
};
Blockly.Arduino.controls_whileUntil = function(){
// Do while/until loop.
var until = block.getFieldValue('MODE') == 'UNTIL';
var argument0 = Blockly.Arduino.valueToCode(block, 'BOOL',
until ? Blockly.Arduino.ORDER_LOGICAL_NOT :
Blockly.Arduino.ORDER_NONE) || 'false';
var branch = Blockly.Arduino.statementToCode(block, 'DO');
if (Blockly.Arduino.INFINITE_LOOP_TRAP) {
branch = Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,
'\'' + block.id + '\'') + branch;
}
if (until) {
argument0 = '!' + argument0;
}
return 'while (' + argument0 + ') {\n' + branch + '}\n';
}

Loading…
Cancel
Save