[go: up one dir, main page]

0% found this document useful (0 votes)
11 views4 pages

15 Loop Control Statement

The document explains control statements in programming, focusing on 'break', 'continue', and 'pass'. It provides examples of how 'break' exits a loop early, 'continue' skips to the next iteration, and 'pass' serves as a placeholder. Additionally, it includes Python code snippets demonstrating these concepts.

Uploaded by

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

15 Loop Control Statement

The document explains control statements in programming, focusing on 'break', 'continue', and 'pass'. It provides examples of how 'break' exits a loop early, 'continue' skips to the next iteration, and 'pass' serves as a placeholder. Additionally, it includes Python code snippets demonstrating these concepts.

Uploaded by

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

2/9/25, 12:50 PM Revolutionizing the Job Market | NxtWave

Cheat Sheet

Loop Control Statements


Control statements alter the sequential execution of a program.

Examples

if-elif-else

while, for

break, continue

Break

Break statement makes the program exit a loop early.

Using Break

Generally, break is used to exit a loop when a condition is satisfied.

In the below example, when the variable

i value equals to 3 the break statement gets executed and stops the execution of the loop further.

Code

PYTHON
https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=e322db60-81d5-42bc-910a-5c832956b5a5&s_id=e10a932f-caf… 1/4
2/9/25, 12:50 PM Revolutionizing the Job Market | NxtWave
PYTHON

1 for i in range(5):
2 if i == 3:
3 break
4 print(i)
5 print("END")

Output

0
1
2
END

Break in Nested Loop

Break in inner loop stops the execution of the inner loop.

Continue

Continue makes the program skip the remaining statements in the current iteration and begin the next iteration.

Using Continue

Generally, continue is used to skip the remaining statements in the current iteration when a condition is satisfied.

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=e322db60-81d5-42bc-910a-5c832956b5a5&s_id=e10a932f-caf… 2/4
2/9/25, 12:50 PM Revolutionizing the Job Market | NxtWave

In the below example, when the variable

i value equals to 3 the next statements in the loop body are skipped.

Code
PYTHON

1 for i in range(5):
2 if i == 3:
3 continue
4 print(i)
5 print("END")

Output

0
1
2
4
END

Pass

Pass statement is used as a syntactic placeholder. When it is executed, nothing happens.

Generally used when we have to test the code before writing the complete code.

Empty Loops

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=e322db60-81d5-42bc-910a-5c832956b5a5&s_id=e10a932f-caf… 3/4
2/9/25, 12:50 PM Revolutionizing the Job Market | NxtWave

We can use pass statements to test code written so far, before writing loop logic.

Submit Feedback

https://learning.ccbp.in/course?c_id=a6454e48-d030-4d49-8920-253198052232&t_id=e322db60-81d5-42bc-910a-5c832956b5a5&s_id=e10a932f-caf… 4/4

You might also like