If Statements

226 views
Skip to first unread message

mehmet sinoplu

unread,
Feb 24, 2015, 2:09:18 AM2/24/15
to blo...@googlegroups.com
Can you add the feature below to Blockly about if statements.

x= 48

if (x%7):
   print "A"
else:
   print "B"

Neil Fraser

unread,
Feb 24, 2015, 2:17:34 AM2/24/15
to blo...@googlegroups.com
Mehmet, please try to solve your problems yourself before posting to the 1000 people subscribed to this newsgroup.  Thank you.

--
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.



--

mehmet sinoplu

unread,
Mar 6, 2015, 12:52:21 PM3/6/15
to blo...@googlegroups.com, ro...@neil.fraser.name
Neil,  I am so sorry. I don't know how to solve it. Therefore I need to ask you. I think the feature I mentioned is an important one because in the example you showed me below it prints "B". However the code block below is normally supposed to print "A". It would be nice to use if statements without using =,>,< etc. in blockly, because in blockly you have to compare something with something to use if statements. Thank you Neil.

x= 48
if (x%7):
   print "A"
else:
   print "B"




24 Şubat 2015 Salı 09:17:34 UTC+2 tarihinde Neil Fraser yazdı:

Erik Pasternak

unread,
Mar 6, 2015, 4:11:34 PM3/6/15
to blo...@googlegroups.com, ro...@neil.fraser.name
Mehmet, just switch "A" and "B". 'is divisible by' corresponds to the remainder being 0 which is what you were testing for the "B" case. Blockly syntax strictly uses boolean instead of mapping 0/null to false and non-zero/non-null to true like JS.

cireyoretihw

unread,
Mar 7, 2015, 9:03:17 PM3/7/15
to blo...@googlegroups.com, ro...@neil.fraser.name
just to clear up the side effect of x%7
                             that when x is a multiple of 7 and therefore x%7 = 0 then print "A"
which means any number not 0 is FALSE 

but i am more use to the opposite in most computer languages but i have not work long with Javascript so i not sure how it works
                               [  0 = FALSE and not 0 is TRUE ]
                                          [ but if you wish to fix  maybe not allowing the if conditions test without It  using =,>,< etc. ]




On Friday, March 6, 2015 at 9:52:21 AM UTC-8, mehmet sinoplu wrote:

Mark Friedman

unread,
Mar 9, 2015, 1:53:18 PM3/9/15
to blo...@googlegroups.com
If you read Mehmet's example you can see that he sets 'x' to 48, so if Blockly supported plugging numbers into boolean slots then his interpretation would work for JavaScript.  So, what I believe Mehmet is asking for is that ability to plug numerical expressions into boolean slots.  That's a reasonable request, and he could fairly easily customize Blockly to support that for his use.  That said, I don't think it would be a good idea for the default version of Blockly.

-Mark

cireyoretihw

unread,
Mar 9, 2015, 9:40:11 PM3/9/15
to blo...@googlegroups.com
so are you saying that it would be nice to replace a condition test with a numeric equation would be a good idea

BUT is a ZERO value the same as a TRUE in the IF statement 

most machine languages use ZERO as a FALSE result but i quess JAVASCRIPT ( BLOCKLY ) can behave differently but i have not seen any SYNTAX rules for them .... can anyone verify this as i have always assumed them to follow normal computer rules ...

Erik Pasternak

unread,
Mar 10, 2015, 11:23:54 AM3/10/15
to blo...@googlegroups.com

Blockly is not equating 0 to true. The statement "is divisible by" is equivalent to "x % y == 0" since it's checking for divisibility and returning true if it is divisible.

If you tried to plug just 0 in to a boolean it wouldn't work, because Blockly is somewhat typed.

You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/CoJBUyXVb6A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+u...@googlegroups.com.

Mark Friedman

unread,
Mar 10, 2015, 2:14:26 PM3/10/15
to blo...@googlegroups.com
On Mon, Mar 9, 2015 at 6:40 PM, cireyoretihw <cireyo...@gmail.com> wrote:
so are you saying that it would be nice to replace a condition test with a numeric equation would be a good idea

No.  I'm saying that it wouldn't be too difficult to create a custom version of Blockly to enable placing blocks representing numeric expressions into boolean sockets.  I explicitly said, however, that I don't think it would be a good idea to do that for the default, standard version of Blockly.


BUT is a ZERO value the same as a TRUE in the IF statement 

most machine languages use ZERO as a FALSE result but i quess JAVASCRIPT ( BLOCKLY ) can behave differently but i have not seen any SYNTAX rules for them .... can anyone verify this as i have always assumed them to follow normal computer rules ...

JavaScript does treat 0 as a false value in boolean contexts and treats non-zero numeric values as true values. And Mehmet's example demonstrates that. 

-Mark

cireyoretihw

unread,
Mar 11, 2015, 2:23:26 AM3/11/15
to blo...@googlegroups.com

sorry i still not sure you are talking the same logic

i see it that mehmet sinoplu is saying

     IF ( x%7 ) then print A

which means that x must be divided by 7 evenly which results in a 0 value which to me means that a numeric expression evaluated to ZERO is a TRUE statement

if this is wrongly stated then please have some one create a BLOCKLY image of how you want the IF BLOCK should look like


i wish more visual BLOCKLY was used instead of JAVASCRIPT code when talking about BLOCKLY

i think this is what you are need make:

cireyoretihw

unread,
Mar 11, 2015, 2:24:28 AM3/11/15
to blo...@googlegroups.com



On Monday, February 23, 2015 at 11:09:18 PM UTC-8, mehmet sinoplu wrote:
Message has been deleted

mehmet sinoplu

unread,
Mar 11, 2015, 3:07:02 AM3/11/15
to blo...@googlegroups.com
My main point in opening this discussion is that I think mathematical expressions should be evaluated in if statements and I wish Blockly should treat 0 value as false, non-zero value as true. For example,

x= 49
if x%7:

   print "A"
else:
   print "B"

Blockly prints it as "A", because it thinks that 49 is divisible by 7 so treats this as true and prints "A". However, 49%7 equals 0 and 0 means false so it should actually print "B".

cireyoretihw

unread,
Mar 11, 2015, 4:39:54 PM3/11/15
to blo...@googlegroups.com
sorry again but since i can't find a version of BLOCKLY that you are using

i can not test out how x%7 works

i thought you were asking if anyone could make it work and as i read the JAVASCRIPT code you are using
and what you say

then

IF ! x%7 == 0
     then Print "IS NOT dividable by 7"
     else Print "IS a multiple of 7"

and you wish to have BLOCKLY

IF x%7
     then Print "IS NOT dividable by 7"
     else Print "IS a multiple of 7"


i am sorry i did not understand what PRINT "A" was trying to describe the point you were trying to make

BTW if you can point to the version of BLOCKLY that x%7 works because it would help understand things better

cireyoretihw

unread,
Mar 11, 2015, 4:52:03 PM3/11/15
to blo...@googlegroups.com

for x in range( 48 , 51):
 
    if ( x%7 ) :

         print "A"
    else
         print "B"


OUTPUT :
     ABA


but are you expecting
    BAB



On Monday, February 23, 2015 at 11:09:18 PM UTC-8, mehmet sinoplu wrote:
Reply all
Reply to author
Forward
0 new messages