Week 04
Conditional Statements, Repeat Loops
Back Then Schematic >>> Now Faster to Prototype! >>> Real World!
Was there IoT in 2009??
Conditional Statements
How does computer language make different decision? So far we learned setup() : something happens at the start, draw(): something same event happens over and over. Also we learned event function like : mousepressed.
Something changes over time.
Today we want to learn something that happens different from previous event. For example, the color of the ellipse changes after one draw, the position of the rectangle change over based on the position of the user's mouse.
Conditional Logic/ Control Structure
if something is true : Do this code
if something is not true : Don't do this code
Boolean Expression (George Boole) : True / False


TRUE
FALSE
1
0
Relational Operator
5 > 8 : False
7 < 210 : True
<
>
=
Greater Than
Less Than
Equal To
if statement
https://editor.p5js.org/kdoodoo/sketches/HJ-xqZyc7
Computer Language != Mathematical Expression
Greater Than
Less Than
Equal To
Not Equal To
Greater Than
or Equal To
Less Than or
Equal To
<
>
=
≠
≤
≥
<
>
==
!=
<=
>=
+
‒
×
÷
+
-
*
/
In-class
Let's make it bouncing! Console.log()
https://editor.p5js.org/kdoodoo/sketches/SJ17zE19Q
Working Great!
if-else statement
https://editor.p5js.org/kdoodoo/sketches/H1Ybrsk9X
if - else if - else if statement
https://editor.p5js.org/kdoodoo/sketches/Bk3fDjycm
if - if - if statement
AND
https://editor.p5js.org/kdoodoo/sketches/By4q0tx5X
100 < mouseX AND mouseX < 200
OR
x < 0 OR x > height
https://editor.p5js.org/kdoodoo/sketches/H1Y3DjJ5X
Repeat Loops
While ...하는 동안
Ellipses one by one....
While loop
https://editor.p5js.org/kdoodoo/sketches/Bk90PLeq7
While loop has 3 components:
Initial Variable
Boolean Condition Test
Incremental Function
For Loop
https://editor.p5js.org/kdoodoo/sketches/B1EHdUlqX
Incremental Methods
For - For Loops
https://editor.p5js.org/kdoodoo/sketches/HJnQTLeq7
Assignment
Make a sketch using both Conditional Statements and Repeat Loops.
https://goo.gl/forms/PcRNuwlkt3quGLng2
Last updated