More Control Structure
Loop Control Structures: while, do
while, for..in
Objectives:
● Create corresponding loop statements to represent the
iterative process.
● Use while, do while, and for..in statements to repeatedly
execute codes.
What is a loop?
While writing a program, you
will encounter a situation
where you would like to
perform an action over and
once again.
We are just going to look at the
while, do while, and the for..in
statements in this learning
module.
while loop
repeats a statement or sequence
of statements as long as they are
evaluated by a given conditional
expression to a truthy value.
while loop
In general, a conditional expression
contains a variable whose value in
the statement code is modified by
one or more statements. Each time
the statements finish executing,
the expression is reevaluated.
do while
executes a statement or
statements once, then repeats the
execution as long as it evaluates
the true value of a given
conditional expression.
do while
syntax
for..in Loop
The for..in loop is a more concise
way of iterating over an object's
properties. The for...in loop will run
for all of the object's elements, and
its syntax will be in the next slide.