Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- operators AND OR NOT && || ! == != what is = vs == if statements else statement elseif switch statements
- First teach AND OR and NOT gates in http://logic.ly/demo
- show how they work with simple switches and lightbulb
- explain that in when we use an AND OR or NOT expression in any langauge, they eventually get put thru an AND OR or NOT gate in the CPU
- (up to here it is done)
- Second in scratch, make examples of AND OR and NOT, perhaps make scratch say something depending on the resurlts of ADN NOT and OR
- like for example say true when true AND ture , say true when flase OR ture , say false when false of false
- http://beta.scratch.mit.edu/projects/10067409/
- explain variables and the difference between = and ==
- have 3dpl draw a red cube if varibale a==5 else draw a green cube... change the value of a so that the user can see the operations taking place
- Mention that in these examples, a green cube means true, and a red cube means false
- Explain that // is a comment in C style languages and { opens a block of code } closes the block
- 3dpl Declarations:
- qb("ACube",0,0,0);//makes a cube
- var a=5;//in this case = is an assignbment, put 5 into a. change 5 to 3 to see the cube change from green to red
- if(a==5) {//in this case == is a comparison, which is true if a is equal to 5 and is false if a is not equal to 5
- cl("ACube", Color.green);//colors a cube green
- } else {
- cl("ACube", Color.red);//colors a cube red
- }
- explain !=, explain that the '!' sign is usually called NOT in C style langauges
- 3dpl Declarations:
- qb("ACube",0,0,0);//makes a cube
- var a=5;//change 5 to 3 to see the cube change from red to green
- if(a==5) {//in this case != is a comparison, which is true if a is not equal to 5 and is false if a is not equal to 5
- cl("ACube", Color.green);//colors a cube green
- } else {
- cl("ACube", Color.red);//colors a cube red
- }
- Third: in 3dpl explain the same things, but now with C style syntax
- and explain just plain not operator !
- 3dpl Declarations:
- qb("ACube",0,0,0);//makes a cube
- var a=1;//change 1 to 0 to see the cube turn from red to green
- if(!(a==1)) { //when a is 1 (a==1) is true, so by saying NOT ture, it actually ends up being false, so we should get a red cube
- cl("ACube", Color.green);//colors a cube green
- } else {
- cl("ACube", Color.red);//colors a cube red
- }
- && AND
- 3dpl Declarations:
- qb("ACube",0,0,0);//makes a cube
- var a=1;//try a=0 and b=1, also a=1 and b=0, also b=0 and a=0
- var b=1;
- if((a==1)&&(b==1)) {//when a is 1 (a==1) is true, when b is 1 (b==1) is true, so (a==1) AND (b==1) is true
- cl("ACube", Color.green);//colors a cube green
- } else {
- cl("ACube", Color.red);//colors a cube red
- }
- || OR
- 3dpl Declarations:
- qb("ACube",0,0,0);//makes a cube
- var a=1;//try a=0 and b=1, also a=1 and b=0, also b=0 and a=0
- var b=0;
- if((a==1)||(b==1)) {//when a is 1 (a==1) is true, when b is 0 (b==1) is false, so (a==1) OR (b==1) is true
- cl("ACube", Color.green);//colors a cube green
- } else {
- cl("ACube", Color.red);//colors a cube red
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement