Loops. Discuss the following picture. What is a ‘Loop’? A loop is an order of instructions that A loop is an order of instructions that repeats for many times. Each repetition is called an iteration of the loop. Terminology PART loop iteration
қайталау / итерация
|
повторение
| divisible ascending counter even odd to fix Coding for loops: Activity Coding for loops: Activity Types of Loops
For loop
While
do...while
Repeats a statement or group of statements until a given condition in use. It tests the condition BEFORE executing the body.
Execute the sequence of statements multiple times.
Like a while statement, except that it tests the condition at the END of the loop body.
Parts of a loop
Initialization Expression initializes the loop variables in the beginning of the loop.
Test Expression decides whether the loop will be executed (if test expression is true) or not (if test expression is false).
Update Expression updates the values of loop variables after every iteration of the loop.
The-Body-of-the-Loop contains statements to be executed repeatedly.
The syntax:
C++
Python
for value in sequence:
body of for
C++
Python
Mark Zuckerberg teaches Loops
Thanks! Any questions?
Достарыңызбен бөлісу: |