# Forums.MrPLC.com: question about boolean and integer - Forums.MrPLC.com

Page 1 of 1

## question about boolean and integer how to use this code Rate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://forums.mrplc.com/index.php?s=878b5eaae292b85642946ad42acddc98&amp;app=forums&module=ajax&section=topics&do=rateTopic&t=18093&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1   biglam106  Posted 19 August 2009 - 12:28 PM

• Sparky
• Group: MrPLC Member
• Posts: 17
• Joined: 04-March 09
• Country:Vietnam
hi every body !
i have a problem
i don't understand this code ( demos files " bakery" )

if FlourTank < 100 && !MoveMan then
MoveMan = 1
endif

if MoveMan then
if MoveMan < 5 then
MoveMan = MoveMan + 1
else
MoveMan = 1
FlourTank = FlourTank + 10
endif

my question is :
1. MoveMan = integer ( 1 to 10 ) and ( ! = not ) therefore the code "!MoveMan" = what's this ?

if FlourTank < 100 && !MoveMan then
MoveMan = 1
value = what's this ( boolean or integer )

if TankOpen && FlourTank then
MillerOpen = FALSE
if Miller < 100 then
FlourTank = FlourTank - 5
Miller = Miller + 5
else
TankOpen = FALSE
endif
else
TankOpen = FALSE
endif

- tankopen = boolean
- flourtank = integer
=> why to use " TankOpen && FlourTank " therefore what is new value of the expression ?

This post has been edited by biglam106: 19 August 2009 - 12:54 PM

UNIVERSITY OF TECHNICAL EDUCATION HCM CITY
TO BE OR NOT TO BE
0

### #2   Berti Baker  Posted 21 August 2009 - 03:03 PM

• Sparky
• Group: MrPLC Member
• Posts: 220
• Joined: 26-July 06
• Country:United Kingdom
Hi Biglam,

I think I can see your confusion - all about mixing boolean expressions with integer operands. Hopefully I can help it make sense

Firstly "!MoveMan" is just a shorter way of saying "!MoveMan == TRUE" or rather "MoveMan != FALSE". Now recognise that Boolean "FALSE" is always value 0, and Boolean "TRUE" is anything that is not 0 (although traditionally TRUE is 1, or -1, or 0xFFFF). So in psuedo code this line means "If the flour tank is not full, and the Man is not moving then start moving the Man"

Actually there's the same issue later with the line "IF MoveMan THEN..." which is again shorthand for "IF MoveMan == TRUE THEN..." or rather "IF MoveMan != FALSE THEN...". Basically meaning "if the man is moving then..."

So any integer can be used as a boolean expression (or with Boolean operators) where zero value means FALSE, or any other value evaluates to TRUE. (Why didn't I just say that! )

The same for "TankOpen && FlourTank" which again really means "TankOpen && (FlourTank != 0)" i.e. "if the valve is open, and there is flour in the tank..."

Even more confused or does that sort it?
Regards,
Bertie

This post has been edited by Berti Baker: 29 August 2009 - 10:51 AM

0

### #3   Sleepy Wombat  Posted 24 August 2009 - 05:38 AM

• Controls Engineer
• Posts: 1,940
• Joined: 09-October 03
• Gender:Male
• Location:Sydney, NSW
• Country:Australia
Good response there Berti... and yes you are absolutely correct...
www.dexa.com.au - Design Engineering Xtreme Automation - DEXA Pty Ltd ** Automating the World Around You **
www.wi-count.com.au - WI-COUNT Wireless Counting Technologies ** Wireless People Counting **

0