Page 100 - Computer - 8
P. 100
Lab Activity 11
Experiential Learning
To display all numbers from 1 to 10, except multiples of 3, using While loop.
1. Type the code as shown in the image in the Python Editor.
2. Press the F5 key to execute the code. Sample output of the program is given below.
Database Subject Enrichment
All programming languages support the concept of loops. A loop can be either a Pre-tested loop or a
Post-tested loop. A Pre-tested loop evaluates the test expression and executes the body of the loop only if
the result of the expression evaluates to True. A Post-tested loop executes the body of the loop at least once
and checks the text expression after the execution. If it evaluates to True, the loop gets executed again, else it
terminates. While loop is an example of a Pre-tested loop, while For loop is an example of a Post-tested loop.
Post-Processing
Iterative statements, or loops, are statements that are executed a specified number of times or
until a specified condition is True.
The For loop is used when the number of times the loop is to be executed is known beforehand.
The Range( ) function is used to specify a range of values which are assigned in sequence to the
counter variable in the For loop.
The While loop in Python is used to execute a set of instructions repeatedly until a certain
condition is satisfied.
Jump statements let the execution control jump to a specific position in the program.
98