Multiple AND OR Condition

897 views
Skip to first unread message

Kalpesh Rathod

unread,
Jun 20, 2016, 4:00:17 PM6/20/16
to Blockly
Hi,

I was building block for multiple AND and OR condition

For example

("A" == "A" OR "B" == "B" OR "C" == "C") OR ("K" == "K" AND "P" == "P")

How would be the block of above condition ?

Attached is similar kind of representation.

Am I doing right or there is better way ?

is it possible to achieve only IF block ?

Thanks
Kalpesh

Blockly-Multipe-AND_OR.png

Daaron Dwyer

unread,
Jun 20, 2016, 4:15:28 PM6/20/16
to blo...@googlegroups.com
While there isn't a block to do more than two and/or tests, there is one to do two, like the image attached.
You can, of course make a logic list block...
2016-06-20_15-13-13.png

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adrian Buzea

unread,
Jun 28, 2016, 9:09:47 AM6/28/16
to Blockly
Here's a multiple AND control that I have created and seems to do what you want. 

Daaron Dwyer

unread,
Jun 28, 2016, 9:17:30 AM6/28/16
to Blockly
I like what you have, I would only change to have the ability to select between AND and OR.

On Tue, Jun 28, 2016 at 8:09 AM Adrian Buzea <kri...@gmail.com> wrote:
Here's a multiple AND control that I have created and seems to do what you want. 

Adrian Buzea

unread,
Jun 28, 2016, 9:24:08 AM6/28/16
to Blockly
You just need to add a dropdown field where you select the operation instead of the plain text. 

Kalpesh Rathod

unread,
Aug 22, 2016, 2:26:20 PM8/22/16
to Blockly
Thanks for Multiple IF/Else condition block..

Do you have code for generator as well ?

the standards  "control_if" does not work if we plug in this "AND" or "OR" multiple condition.

When i add alert on "Argument" it just return "C"  so it forms if(C) { ......}

Any quick help highly apreciated ?


Blockly.JavaScript['controls_if'] = function(block) {
    // If/elseif/else condition.

    alert(block);

  var n = 0;
  var argument = Blockly.JavaScript.valueToCode(block, 'IF' + n,
      Blockly.JavaScript.ORDER_NONE) || 'false';
  var branch = Blockly.JavaScript.statementToCode(block, 'DO' + n);

  alert('Argument  ' + argument);

 
  var code = 'if (' + argument + ') {\n' + branch + '}';
  for (n = 1; n <= block.elseifCount_; n++) {
    argument = Blockly.JavaScript.valueToCode(block, 'IF' + n,
        Blockly.JavaScript.ORDER_NONE) || 'false';
    branch = Blockly.JavaScript.statementToCode(block, 'DO' + n);
    code += ' else if (' + argument + ') {\n' + branch + '}';
  }
  if (block.elseCount_) {
    branch = Blockly.JavaScript.statementToCode(block, 'ELSE');
    code += ' else {\n' + branch + '}';
  }


  return code + '\n';
};
Blockly-Multipe-AND_OR-1.png

Stefan Höhn

unread,
Sep 16, 2025, 1:57:12 AM (3 days ago) Sep 16
to Blockly
Adrian Buzea:
Would you mind if I used your code for an open source project to extend our library? I presume as you posted it, it is open source and fair to use? I will attribute it to you.

ewpa...@gmail.com

unread,
Sep 17, 2025, 2:19:48 PM (yesterday) Sep 17
to Blockly
App Inventor also has mutatable and/or blocks with a dropdown (ref). Our sources are Apache 2 licensed if that would work for you.

Regards,
Evan
Reply all
Reply to author
Forward
0 new messages