Quick Index
What Is A Loop Statement?


Recall the definition of condition.

A loop statement is a conditional expression followed by a code block that executes while the conditional expression is true.

The next examples will explain.

Algorithmic Perspective


General
While the condition (expression) is true code "A" repeatedly evaluates (runs).
While (CONDITION) {
	//CODE "A"
}
Specific Example
The condition is "a > b".

Thus, "while" the element "a" is greater than the element "b", then code "A" repeatedly evaluates (runs).
While (a > b) {
	//CODE "A"
}


Everyday Loops



The loop terminates when the condition goes false.

Condition
Incrementor
Action (Code Block
While True)
Any problems remaining?
move to next problem
work on problem
Are we there yet? (biking)
move to next mile
peddle peddle
Semester over?
move to next day
work work
Any pizza left?
next slice
eat slice

While True


The condition is either true else it is false.

Purpose
Initialization
Condition
Incrementor
Run
Code Block
While True
Print Numbers
initialize n = 1
n <= 100
increment n
print n
Sum Numbers
"initialize n = 1
initialize sum = 0"
n <= 10
increment n
sum = sum + n