0% found this document useful (0 votes)
27 views9 pages

CCD Module14-PL101 01

programming language

Uploaded by

darwinteberio0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views9 pages

CCD Module14-PL101 01

programming language

Uploaded by

darwinteberio0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

INFORMATION SHEET PL 101-14.1.

In this lesson, we will learn to use break, continue and pass statements to alter the flow
of a loop.

References:
• Python Programming for Beginners
INFORMATION SHEET PL 101-14.1.1
“Python Break, Continue and Pass”

Python break Statement

The break statement is used to terminate the loop immediately when it is encountered.

The syntax of the break statement is:

break

Working of Python break Statement

The working of break statement in for loop and while loop is shown above.

Swift break Statement with for Loop

We can use the break statement with for loop to terminate the loop when a certain condition is met.

For example,
for i in range(5):
if i == 3:
break
print(i)

Output
0
1
2

In the above example, we have used the for loop to print the value of i. Notice the use of

the break statement,

if i == 3:
break

Here, when i is equal to 3, the break statement terminates the loop. Hence, the output doesn't

include values after 2.

Note: The break statement is almost always used with decision-making statements.

Swift break Statement with while Loop

We can also terminate a while loop using the break statement. For example,
# program to find first 5 multiples of 6

i=1

while (i<=10):
print('6 * ',(i), '=',6 * i)

if i >= 5:
break

i=i+1

Output

6* 1=6
6* 2 = 12
6* 3 = 18
6* 4 = 24
6* 5 = 30

In the above example, we have used the while loop to find the first 5 multiples of 6. Here notice the line,
if i >= 5:
break

This means when i is greater than or equal to 5, the while loop is terminated.

Python continue Statement

The continue statement is used to skip the current iteration of the loop and the control flow of the

program goes to the next iteration.

The syntax of the continue statement is:

continue

Working of Python continue Statement

Swift continue Statement with for Loop

We can use the continue statement with the for loop to skip the current iteration of the loop.

Then the control of the program jumps to the next iteration. For example,
for i in range(5):
if i == 3:
continue
print(i)

Output

0
1
2
4

In the above example, we have used the for loop to print the value of i. Notice the use of

the continue statement,

if i == 3:
continue

Here, when i is equal to 3, the continue statement is executed. Hence, the value 3 is not printed to the

output.

Swift continue Statement with while Loop

In Python, we can also skip the current iteration of the while loop using the continue statement.

For example,

# program to print odd numbers from 1 to 10

num = 0

while num < 10:


num += 1

if (num % 2) == 0:
continue

print(num)

Output

1
3
5
7
9

In the above example, we have used the while loop to print the odd numbers between 1 to 10.

Notice the line,

if (num % 2) == 0:
continue

Here, when the number is even, the continue statement skips the current iteration and starts

the next iteration.

Python pass Statement

In Python programming, the pass statement is a null statement which can be used as a

placeholder for future code.

Suppose we have a loop or a function that is not implemented yet, but we want to implement it
in the future. In such cases, we can use the pass statement.

The syntax of the pass statement is:

pass

Using pass With Conditional Statement

n = 10

# use pass inside if statement


if n > 10:
pass
print('Hello')

Here, notice that we have used the pass statement inside the if statement.

However, nothing happens when the pass is executed. It results in no operation (NOP).

Suppose we didn't use pass or just put a comment as:

n = 10

if n > 10:
# write code later

print('Hello')

Here, we will get an error message: IndentationError: expected an indented block

Note: The difference between a comment and a pass statement in Python is that while the

interpreter ignores a comment entirely, pass is not ignored.

Use of pass Statement inside Function or Class

We can do the same thing in an empty function or class as well. For example,

def function(args):
pass
class Example:
pass

STUDENT NAME: __________________________________ SECTION: __________________

PERFORMANCE TASK PL 101-14.1.1


WRITTEN WORK TITLE:

WRITTEN TASK OBJECTIVE:


MATERIALS:
 Pen and Paper
TOOLS & EQUIPMENT:
 None
ESTIMATED COST: None
Instruction:

PRECAUTIONS:
 Do not just copy all your output from the internet.
 Use citation and credit to the owner if necessary.
ASSESSMENT METHOD: WRITTEN WORK CRITERIA CHECKLIST
STUDENT NAME: _____________________________ SECTION: __________________

PERFORMANCE OUTPUT CRITERIA CHECKLIST PL 101-14.1.1

CRITERIA SCORING
Did I . . .
1 2 3 4 5
1. Focus - The single controlling point made with an awareness of a
task about a specific topic.
2. Content - The presentation of ideas developed through facts,
examples, anecdotes, details, opinions, statistics, reasons, and/or
opinions
3. Organization – The order developed and sustained within and
across paragraphs using transitional devices and including the
introduction and conclusion.
4. Style – The choice, use, and arrangement of words and sentence
structures that create tone and voice.
5. .
6. .
7. .
8. .
9. .
10. .
TEACHER’S REMARKS:  QUIZ  RECITATION 
PROJECT
GRADE:

5 - Excellently Performed
4 - Very Satisfactorily Performed
3 - Satisfactorily Performed
2 - Fairly Performed
1 - Poorly Performed

_______________________________
TEACHER

Date: ______________________

You might also like