ITK 168 Decisions Dr. Doug Twitchell September 20, 2005
IF What if I want the robot to pick a thing up if there’s one there, but not pick a thing up if there isn’t?
if if(bob.canPickThing()){ bob.pickThing(); } if( >){ > }
if if(bob.canPickThing()){ bob.pickThing(); } if( >){ > } boolean statement
if if(bob.canPickThing()){ bob.pickThing(); } if( >){ > } boolean statement true or false
if Flowchart
if Can I use this to see if there is a wall in front of me?
if if(bob.frontIsClear()){ bob.move(); } bob.turnLeft(); bob.move(); > if( >){ > } >
if What if I want it to left if the front isn’t clear?
if if(!bob.frontIsClear()){ bob.turnLeft(); } bob.move(); > if( >){ > } >
if Can I check to see if the robot is on a certain street?
if if(bob.getStreet == 1){ bob.move(); } if( >){ > } == equal > greater than < less than >= g.t. or equal <= l.t. or equal != not equal
while what if I want the robot to pick up all of the things in a row
while while(bob.canPickThing()){ bob.pickThing(); bob.move(); } while( >){ > }
while while(bob.canPickThing()){ bob.pickThing(); bob.move } while( >){ > } boolean statement true or false
while Flowchart
while How about moving the robot until it gets to avenue 50?
while while(bob.getAvenue() < 50){ bob.move } while( >){ > }
if…else What about when want to turn right if wall is in front and turn left otherwise?
if…else if(bob.frontIsClear()){ bob.turnLeft(); } else { bob.turnRight(); } bob.move(); if( >){ > } boolean statement true or false
if…else Flowchart
Example How can we change the street cleaning robots to make it work better with if and/or while statements?