Download - MzTEK Programming - Part 2
![Page 1: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/1.jpg)
![Page 2: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/2.jpg)
REVIEW LAST WEEK
![Page 3: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/3.jpg)
Think of idea
Break down problem into tiny steps
Write code for one step
Run program
![Page 4: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/4.jpg)
Code You’ve Written
Instructions for Computer?
Executable Program (e.g. .exe or .app)
Interactive Development
Environment (IDE)
Compiler +
Linker +
Loader
![Page 5: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/5.jpg)
int x;int y;int width;int height;
size(200, 200);
x = 150;y = 100;width = 90;height = 80;
ellipse(x, y, width, height);
![Page 6: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/6.jpg)
int x;int y;int width;int height;
size(200, 200);
x = 150;y = 100;width = 90;height = 80;
ellipse(x, y, width, height);
ingredients or variables
![Page 7: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/7.jpg)
int x;int y;int width;int height;
size(200, 200);
x = 150;y = 100;width = 90;height = 80;
ellipse(x, y, width, height);
ingredients or variables
directions or algorithm
![Page 8: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/8.jpg)
int x;int y;int width;int height;
size(200, 200);
x = 150;y = 100;width = 90;height = 80;
ellipse(x, y, width, height);
ingredients or variables
directions or algorithm
data type
![Page 9: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/9.jpg)
int x;int y;int width;int height;
size(200, 200);
x = 150;y = 100;width = 90;height = 80;
ellipse(x, y, width, height);
ingredients or variables
directions or algorithm
data type variable name
![Page 10: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/10.jpg)
DECLARATION VS INITIALISATIONAs in a recipe, ingredients need to be listed at the top so you know what to buy.
In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
![Page 11: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/11.jpg)
DECLARATION VS INITIALISATIONAs in a recipe, ingredients need to be listed at the top so you know what to buy.
In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
int myInt;
Reserve space for an int
![Page 12: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/12.jpg)
DECLARATION VS INITIALISATIONAs in a recipe, ingredients need to be listed at the top so you know what to buy.
In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
We don’t have to know what value will be stored in myInt right away.
We can choose a value later. This is called initialising.
int myInt;
Reserve space for an int
![Page 13: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/13.jpg)
DECLARATION VS INITIALISATIONAs in a recipe, ingredients need to be listed at the top so you know what to buy.
In code, it’s so the compiler knows how much memory to reserve. This is called declaring.
We don’t have to know what value will be stored in myInt right away.
We can choose a value later. This is called initialising.
int myInt;
Reserve space for an int
myInt = 15;
Store the value 15 in the space reserved for myInt
15
![Page 14: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/14.jpg)
Need to declare before or at the same time as initialisation.
![Page 15: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/15.jpg)
Need to declare before or at the same time as initialisation.
myInt = 3;int myInt;
![Page 16: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/16.jpg)
Need to declare before or at the same time as initialisation.
myInt = 3;int myInt;
int myInt; myInt = 3;
![Page 17: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/17.jpg)
Need to declare before or at the same time as initialisation.
myInt = 3;int myInt;
int myInt; myInt = 3;
Can’t use a variable before it is initialised.
![Page 18: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/18.jpg)
Need to declare before or at the same time as initialisation.
myInt = 3;int myInt;
int myInt; myInt = 3;
int myInt;myInt = myInt + 7;
Can’t use a variable before it is initialised.
![Page 19: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/19.jpg)
Need to declare before or at the same time as initialisation.
myInt = 3;int myInt;
int myInt; myInt = 3;
int myInt = 3;myInt = myInt + 7;
int myInt;myInt = myInt + 7;
Can’t use a variable before it is initialised.
![Page 20: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/20.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
floatintchar
![Page 21: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/21.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
floatintchar
to create a float type
![Page 22: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/22.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
floatintchar
to create a float type
to create an int type
![Page 23: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/23.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
floatintchar
to create a float type
to create an int type
to create a char type
![Page 24: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/24.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
floatintchar
to create a float type
to create an int type
to create a char type
![Page 25: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/25.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
floatintchar
to create a float type
to create an int type
to create a char type
float scale;int redValue;char finalMark;
![Page 26: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/26.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
floatintchar
to create a float type
to create an int type
to create a char type
float scale;int redValue;char finalMark;
you get to choose the name
![Page 27: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/27.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
3. If you already know what the value of that variable is, then go ahead and set the value.
floatintchar
to create a float type
to create an int type
to create a char type
float scale;int redValue;char finalMark;
you get to choose the name
![Page 28: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/28.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
3. If you already know what the value of that variable is, then go ahead and set the value.
floatintchar
to create a float type
to create an int type
to create a char type
float scale;int redValue;char finalMark;
float scale = 0.5;int redValue = 199;char finalMark = ‘B’;
you get to choose the name
![Page 29: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/29.jpg)
TO CREATE A VARIABLE1. Decide what the data type should be. Usually the main
decisions are between int, float and char.
2. Decide on a name for your variable. Remember the rules.
3. If you already know what the value of that variable is, then go ahead and set the value.
floatintchar
to create a float type
to create an int type
to create a char type
float scale;int redValue;char finalMark;
float scale = 0.5;int redValue = 199;char finalMark = ‘B’;
if you don’t know the value yet, stop at step 2. but remember to end
each line with a ;
you get to choose the name
![Page 30: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/30.jpg)
EXERCISE
In Processing, draw a purple quadrilateral using the quad( ) function.
quad(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
Use variables to represent corner of the quadrilateral.
![Page 31: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/31.jpg)
ARRAYS
![Page 32: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/32.jpg)
int x0 = 20;int y0 = 20;int x1 = 30;int y1 = 50;int x2 = 150;int y2 = 50;int x3 = 160;int y3 = 20;
size(200, 200);quad(x0, y0, x1, y1, x2, y2, x3, y3);
![Page 33: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/33.jpg)
int x0 = 20;int y0 = 20;int x1 = 30;int y1 = 50;int x2 = 150;int y2 = 50;int x3 = 160;int y3 = 20;
size(200, 200);quad(x0, y0, x1, y1, x2, y2, x3, y3);
this is a pain to keep track of
![Page 34: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/34.jpg)
int x0 = 20;int y0 = 20;int x1 = 30;int y1 = 50;int x2 = 150;int y2 = 50;int x3 = 160;int y3 = 20;
size(200, 200);quad(x0, y0, x1, y1, x2, y2, x3, y3);
this is a pain to keep track of
Wouldn’t it be easier to just have two lists, so only two variable names: “x” and “y”?
![Page 35: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/35.jpg)
X
0.) 20
1.) 30
2.)150
3.)160
Y
0.) 20
1.) 50
2.) 50
3.) 20
What if had a list called X
And a list called Y
![Page 36: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/36.jpg)
X
0.) 20
1.) 30
2.)150
3.)160
Y
0.) 20
1.) 50
2.) 50
3.) 20
What if had a list called X
And a list called Y
So if we just want the number at 2.) in the X list, we’d type
x[2]
![Page 37: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/37.jpg)
X
0.) 20
1.) 30
2.)150
3.)160
Y
0.) 20
1.) 50
2.) 50
3.) 20
What if had a list called X
And a list called Y
So if we just want the number at 2.) in the X list, we’d type
x[2]
That’s all an array is:a list of things, where we don’t have to
name each thing, just the list.
![Page 38: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/38.jpg)
To create a new list (to declare it):
int[] x = new int[4];
![Page 39: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/39.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
![Page 40: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/40.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 41: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/41.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 42: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/42.jpg)
To create a new list (to declare it):
int[] x = new int[4];
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item how long will the list be?
[ ] means the data type is an array
![Page 43: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/43.jpg)
To initialise a new list :
x[0] = 20;x[1] = 30;x[2] = 150;x[3] = 160;
![Page 44: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/44.jpg)
To initialise a new list :
x[0] = 20;x[1] = 30;x[2] = 150;x[3] = 160;
what list are you referring to?
![Page 45: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/45.jpg)
To initialise a new list :
x[0] = 20;x[1] = 30;x[2] = 150;x[3] = 160;
which item from the list?
what list are you referring to?
![Page 46: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/46.jpg)
To initialise a new list :
x[0] = 20;x[1] = 30;x[2] = 150;x[3] = 160;
which item from the list?
what list are you referring to?
what is the value of that item?
![Page 47: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/47.jpg)
int[] x = new int[4];
x[0]
x[1]
x[2]
x[3]
![Page 48: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/48.jpg)
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
x[0]
x[1]
x[2]
x[3]
![Page 49: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/49.jpg)
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item how long will the list be?
x[0]
x[1]
x[2]
x[3]
![Page 50: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/50.jpg)
int[] x = new int[4];
what kind of things are in the list? i.e. how much space needs to be
reserved for each item how long will the list be?
x[0]
x[1]
x[2]
x[3]
the length of the array and the data type determine
how much memory is used
![Page 51: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/51.jpg)
You can declare and initialise a new list at the same time :
int[] x = {20, 30, 150, 160};
![Page 52: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/52.jpg)
You can declare and initialise a new list at the same time :
int[] x = {20, 30, 150, 160};
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
![Page 53: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/53.jpg)
You can declare and initialise a new list at the same time :
int[] x = {20, 30, 150, 160};
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 54: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/54.jpg)
You can declare and initialise a new list at the same time :
int[] x = {20, 30, 150, 160};
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 55: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/55.jpg)
You can declare and initialise a new list at the same time :
int[] x = {20, 30, 150, 160};
what is the value of each item?
what is the name of the list?
what kind of things are in the list? i.e. how much space needs to be
reserved for each item
[ ] means the data type is an array
![Page 56: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/56.jpg)
In Processing, rewrite this code so that it uses two arrays.
EXERCISE
int x0 = 20;int y0 = 20;int x1 = 30;int y1 = 50;int x2 = 150;int y2 = 50;int x3 = 160;int y3 = 20;
size(200, 200);quad(x0, y0, x1, y1, x2, y2, x3, y3);
![Page 57: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/57.jpg)
CONTROL STRUCTURES
![Page 58: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/58.jpg)
1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil from the jar6 rashers of smoked streaky bacon, chopped2 large onions, chopped3 garlic cloves, crushed1kg/2¼lb lean minced beef2 large glasses of red wine2x400g cans chopped tomatoes1x290g jar antipasti marinated mushrooms, drained2 fresh or dried bay leaves
1 tsp dried oregano or a small handful of fresh leaves, chopped1 tsp dried thyme or a small handful of fresh leaves, choppedDrizzle balsamic vinegar12-14 sun-dried tomato halves, in oilSalt and freshly ground black pepperA good handful of fresh basil leaves, torn into small pieces800g-1kg/1¾-2¼lb dried spaghettiLots of freshly grated parmesan, to serve
![Page 59: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/59.jpg)
1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil from the jar6 rashers of smoked streaky bacon, chopped2 large onions, chopped3 garlic cloves, crushed1kg/2¼lb lean minced beef2 large glasses of red wine2x400g cans chopped tomatoes1x290g jar antipasti marinated mushrooms, drained2 fresh or dried bay leaves
1 tsp dried oregano or a small handful of fresh leaves, chopped1 tsp dried thyme or a small handful of fresh leaves, choppedDrizzle balsamic vinegar12-14 sun-dried tomato halves, in oilSalt and freshly ground black pepperA good handful of fresh basil leaves, torn into small pieces800g-1kg/1¾-2¼lb dried spaghettiLots of freshly grated parmesan, to serve
![Page 60: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/60.jpg)
1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil from the jar6 rashers of smoked streaky bacon, chopped2 large onions, chopped3 garlic cloves, crushed1kg/2¼lb lean minced beef2 large glasses of red wine2x400g cans chopped tomatoes1x290g jar antipasti marinated mushrooms, drained2 fresh or dried bay leaves
1 tsp dried oregano or a small handful of fresh leaves, chopped1 tsp dried thyme or a small handful of fresh leaves, choppedDrizzle balsamic vinegar12-14 sun-dried tomato halves, in oilSalt and freshly ground black pepperA good handful of fresh basil leaves, torn into small pieces800g-1kg/1¾-2¼lb dried spaghettiLots of freshly grated parmesan, to serve
![Page 61: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/61.jpg)
1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil from the jar6 rashers of smoked streaky bacon, chopped2 large onions, chopped3 garlic cloves, crushed1kg/2¼lb lean minced beef2 large glasses of red wine2x400g cans chopped tomatoes1x290g jar antipasti marinated mushrooms, drained2 fresh or dried bay leaves
1 tsp dried oregano or a small handful of fresh leaves, chopped1 tsp dried thyme or a small handful of fresh leaves, choppedDrizzle balsamic vinegar12-14 sun-dried tomato halves, in oilSalt and freshly ground black pepperA good handful of fresh basil leaves, torn into small pieces800g-1kg/1¾-2¼lb dried spaghettiLots of freshly grated parmesan, to serve
We’ve covered how to create ingredients or variables.
![Page 62: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/62.jpg)
1. Heat the oil in a large, heavy-based saucepan and fry the bacon until golden over a medium heat. Add the onions and garlic, frying until softened. Increase the heat and add the minced beef. Fry it until it has browned, breaking down any chunks of meat with a wooden spoon. Pour in the wine and boil until it has reduced in volume by about a third. Reduce the temperature and stir in the tomatoes, drained mushrooms, bay leaves, oregano, thyme and balsamic vinegar.
2. Either blitz the sun-dried tomatoes in a small blender with a little of the oil to loosen, or just finely chop before adding to the pan. Season well with salt and pepper. Cover with a lid and simmer the Bolognese sauce over a gentle heat for 1-1½ hours until it's rich and thickened, stirring occasionally. At the end of the cooking time, stir in the basil and add any extra seasoning if necessary.
3. Remove from the heat to 'settle' while you cook the spaghetti in plenty of boiling salted water (for the time stated on the packet). Drain and divide between warmed plates. Scatter a little parmesan over the spaghetti before adding a good ladleful of the Bolognese sauce, finishing with a scattering of more cheese and a twist of blackhttp://www.bbc.co.uk/food/recipes/spaghettibolognese_67868
2 tbsp olive oil or sun-dried tomato oil from the jar6 rashers of smoked streaky bacon, chopped2 large onions, chopped3 garlic cloves, crushed1kg/2¼lb lean minced beef2 large glasses of red wine2x400g cans chopped tomatoes1x290g jar antipasti marinated mushrooms, drained2 fresh or dried bay leaves
1 tsp dried oregano or a small handful of fresh leaves, chopped1 tsp dried thyme or a small handful of fresh leaves, choppedDrizzle balsamic vinegar12-14 sun-dried tomato halves, in oilSalt and freshly ground black pepperA good handful of fresh basil leaves, torn into small pieces800g-1kg/1¾-2¼lb dried spaghettiLots of freshly grated parmesan, to serve
We’ve covered how to create ingredients or variables.
Now onto the basics of how to use those variables.
![Page 63: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/63.jpg)
HOW TO MAKE A DECISION
![Page 64: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/64.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
![Page 65: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/65.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
<
![Page 66: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/66.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
<less than
![Page 67: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/67.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
7 4<less than
![Page 68: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/68.jpg)
FALSE
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
7 4<less than
![Page 69: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/69.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
![Page 70: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/70.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
>
![Page 71: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/71.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
>greater than
![Page 72: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/72.jpg)
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
7 4>greater than
![Page 73: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/73.jpg)
TRUE
HOW TO MAKE A DECISIONOnce we have some variables, we want to do things with those variables.
The most basic step is to compare those variables to something else.
This is done with comparators - questions that can be answered yes or no (or true or false).
7 4>greater than
![Page 74: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/74.jpg)
OTHER COMPARISONS
>=
<=
==
!=
greater than or equal to
less than or equal to
equal to
not equal to
All of these result in true or false.
![Page 75: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/75.jpg)
if ( ) {
}else {
}
![Page 76: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/76.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
![Page 77: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/77.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
what to do if our comparison statement is true
![Page 78: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/78.jpg)
if ( ) {
}else {
}
put in a comparison statement (like < or >)
what to do if our comparison statement is true
what to do if our comparison statement is false
![Page 79: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/79.jpg)
if ( ) {
}else {
}
we don’t have to always have an else
statement, sometimes you only care if the statement is true
put in a comparison statement (like < or >)
what to do if our comparison statement is true
what to do if our comparison statement is false
![Page 80: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/80.jpg)
If something is true, do an action.
![Page 81: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/81.jpg)
If something isn’t true, instead do a different action.
If something is true, do an action.
![Page 82: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/82.jpg)
If something isn’t true, instead do a different action.
If something is true, do an action.
If the potatoes are too lumpy, keep mashing.
![Page 83: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/83.jpg)
If something isn’t true, instead do a different action.
If something is true, do an action.
If the potatoes are too lumpy, keep mashing.
If the potatoes are not too lumpy, stop mashing.
![Page 84: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/84.jpg)
If something isn’t true, instead do a different action.
If something is true, do an action.
If the potatoes are too lumpy, keep mashing.
If the potatoes are not too lumpy, stop mashing.
We don’t have to test this twice. We know if the potatoes are either too lumpy or not too
lumpy.
![Page 85: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/85.jpg)
When graphing information, we are used to numbers
A NOTE ON AXES
![Page 86: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/86.jpg)
When graphing information, we are used to numbers
increasing as we move right
A NOTE ON AXES
![Page 87: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/87.jpg)
When graphing information, we are used to numbers
and increasing as we move up
increasing as we move right
A NOTE ON AXES
![Page 88: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/88.jpg)
A NOTE ON AXES
This is different to how numbers work with programming graphics.
![Page 89: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/89.jpg)
A NOTE ON AXES
This is different to how numbers work with programming graphics.
Numbers start in the upper left corner at the
origin (0, 0)
![Page 90: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/90.jpg)
A NOTE ON AXES
This is different to how numbers work with programming graphics.
and increase as we move right
Numbers start in the upper left corner at the
origin (0, 0)
![Page 91: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/91.jpg)
A NOTE ON AXES
This is different to how numbers work with programming graphics.
and increase as we move down
and increase as we move right
Numbers start in the upper left corner at the
origin (0, 0)
![Page 92: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/92.jpg)
EXERCISECreate a Processing sketch which draws a green circle if the mouse is in the top half of the window and changes the circle’s colour to red if the mouse in the bottom half of the window. Start with the code below.
void setup() {// create the windowsize(400, 400);
}
void draw() {// set the colourfill(10, 10, 255);
// draw the circleellipse(mouseX, mouseY, 100, 100);
}
![Page 93: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/93.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
![Page 94: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/94.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
![Page 95: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/95.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
counter is only increased if both if statements are true.
![Page 96: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/96.jpg)
What if we want to use multiple if statements?
int counter;// some other code...if (counter < 10) {if (counter > 0 ) {counter++;
}}
If counter is less than 10 and greater than 0, then increase counter by 1.
These are called nested if statements, because one is inside the { } of the other.
counter is only increased if both if statements are true.
![Page 97: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/97.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {}counter = 0;
}
What if we want to use multiple if statements?
![Page 98: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/98.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {}counter = 0;
}
If counter is greater than 10 or less than 0, then reset counter to 0.
What if we want to use multiple if statements?
![Page 99: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/99.jpg)
int counter;// some other code...if (counter > 10) {counter = 0;
}if (counter < 0 ) {}counter = 0;
}
If counter is greater than 10 or less than 0, then reset counter to 0.
counter is reset if either if
statements are true.
What if we want to use multiple if statements?
![Page 100: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/100.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True True
False False
OR
OR
OR
is
is
is
is
![Page 101: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/101.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
![Page 102: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/102.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
True
![Page 103: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/103.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
True True
False False
OR
OR
OR
is
is
is
is
True
True
![Page 104: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/104.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
False
True True
False False
OR
OR
OR
is
is
is
is
True
True
![Page 105: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/105.jpg)
BOOLEAN OPERATOR OR
ORTrue False
TrueFalse
True
False
True True
False False
OR
OR
OR
is
is
is
is
True
True
When using OR in code, type ||
![Page 106: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/106.jpg)
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
![Page 107: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/107.jpg)
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
False
![Page 108: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/108.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
False
![Page 109: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/109.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
True True
False False
AND
AND
AND
is
is
is
is
True
False
![Page 110: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/110.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
False
True True
False False
AND
AND
AND
is
is
is
is
True
False
![Page 111: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/111.jpg)
False
BOOLEAN OPERATOR AND
ANDTrue False
TrueFalse
False
True True
False False
AND
AND
AND
is
is
is
is
True
When using OR in code, type &&
False
![Page 112: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/112.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
is
is
![Page 113: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/113.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
Falseis
is
![Page 114: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/114.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
False
True
is
is
![Page 115: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/115.jpg)
BOOLEAN OPERATOR NOT
NOT True
FalseNOT
False
True
is
is
When using NOT in code, type !
![Page 116: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/116.jpg)
EXERCISEModify your Processing sketch which draws a green circle if the mouse is in the top half of the window and changes the circle’s colour to red if the mouse in the bottom half of the window.
Now using the AND statement, draw
• a green circle in the upper left quadrant of the window,
• a blue circle in the upper right quadrant,
• a red circle in the lower left quadrant,
• and a yellow circle in the lower right quadrant.
![Page 117: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/117.jpg)
LOOPS
![Page 118: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/118.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
![Page 119: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/119.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
Repeat this event in the calendar this
many times.
![Page 120: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/120.jpg)
LOOPS
There are two ways to repeat something:
1. Do this N number of times.
2. Keep doing this until something else happens.
Repeat this event in the calendar this
many times.
Repeat this event in the calendar until a certain
date occurs.
![Page 121: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/121.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
![Page 122: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/122.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
![Page 123: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/123.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
![Page 124: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/124.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
then do whatever is written here
![Page 125: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/125.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
when you’ve done what’s in the { } once, do this, in this case add make i equal to its current value plus 1
then do whatever is written here
![Page 126: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/126.jpg)
DO THIS N TIMES
int i;for(i=0; i<4; i++) {
}
start with a number, in this case 0
if this statement is true
when you’ve done what’s in the { } once, do this, in this case add make i equal to its current value plus 1
then do whatever is written here
go back to see if the middle statement is still
true
![Page 127: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/127.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
![Page 128: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/128.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
![Page 129: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/129.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
then do what is between { } once
![Page 130: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/130.jpg)
KEEP DOING THIS UNTIL SOMETHING ELSE HAPPENS
while ( ) {
}
if the statement here is true
then do what is between { } once
then repeat by checking the statement again
![Page 131: MzTEK Programming - Part 2](https://reader034.vdocuments.us/reader034/viewer/2022051412/54c3056c4a79590c6a8b46c8/html5/thumbnails/131.jpg)
EXERCISEWrite out each iteration of these loops and what the variables equal at the end of each loop.
int i;int j = 15;
for (i=0; i<12; i++) {j = j * 2 - i;
}
int k = 100;
while ( k > 0 ) {k = k -10;
}