2024
Javascript
Control Flow
© 2024 Celerates CELERATES.CO.ID
2024
Content
Conditional Statement
Loops and Interation
© 2024 Celerates CELERATES.CO.ID
2024
Conditional
Statement
© 2024 Celerates
1
CELERATES.CO.ID
Conditional Statement 2024
● JavaScript supports a compact set of
statements, specifically control flow
statements, that you can use to incorporate
a great deal of interactivity in your
application.
© 2024 Celerates CELERATES.CO.ID
2024
If statement
© 2024 Celerates CELERATES.CO.ID
2024
Else if
© 2024 Celerates CELERATES.CO.ID
2024
Else if
© 2024 Celerates CELERATES.CO.ID
2024
Else if
© 2024 Celerates CELERATES.CO.ID
2024
Nesting
We can nest conditionals inside conditionals
© 2024 Celerates CELERATES.CO.ID
2024
Switch Case
Use switch to specify many alternative blocks of code to
be executed
© 2024 Celerates CELERATES.CO.ID
2024
Break statement
● The optional break statement associated with each
case clause ensures that the program breaks out of
switch once the matched statement is executed, and
then continues execution at the statement following
switch. If break is omitted, the program continues
execution inside the switch statement (and will execute
statements under the next case, and so on).
© 2024 Celerates CELERATES.CO.ID
2024
Looping and
Iteration
REPEAT STUFF.
REPEAT STUFF.
REPEAT STUFF.
© 2024 Celerates
2
CELERATES.CO.ID
2024
Loops
● Loops allow us to repeat code
○ "Print 'hello' 10 times
○ Sum all numbers in an array
● There are multiple types:
○ for loop
○ while loop
○ for...of loop
○ for...in loop
© 2024 Celerates CELERATES.CO.ID
2024
For Loops
© 2024 Celerates CELERATES.CO.ID
2024
Our First For Loops
© 2024 Celerates CELERATES.CO.ID
2024
Infinite Loops
© 2024 Celerates CELERATES.CO.ID
2024
Looping Over Arrays
© 2024 Celerates CELERATES.CO.ID
2024
Nested Loops
© 2024 Celerates CELERATES.CO.ID
2024
For of
A nice and easy way of iterating over
arrays
(or other iterable objects)
© 2024 Celerates CELERATES.CO.ID
2024
For of
An Example
© 2024 Celerates CELERATES.CO.ID
2024
For in
JavaScript for in statement loops through the
properties of an Object:
© 2024 Celerates CELERATES.CO.ID
2024
For in
An Example
//John Doe 25
© 2024 Celerates CELERATES.CO.ID
2024
While Loops
© 2024 Celerates CELERATES.CO.ID
2024
Do … While Loops
● The do while loop is a variant of the while
loop. This loop will execute the code block
once, before checking if the condition is
true, then it will repeat the loop as long as
the condition is true.
© 2024 Celerates CELERATES.CO.ID
2024
Do … While Loops
© 2024 Celerates CELERATES.CO.ID
2024
Do … While Loops
An Example
© 2024 Celerates CELERATES.CO.ID
2024
Any question?
© 2024 Celerates CELERATES.CO.ID
2024
© 2024 Celerates CELERATES.CO.ID
2024
GUIDING RESOURCE
Loops and iteration - JavaScript | MDN (mozilla.org)
https://egghead.io/
https://www.javatpoint.com/
© 2024 Celerates CELERATES.CO.ID