Featured

    Featured Posts

Python break, continue statement with for loop

The break Statement In Python:
§  break is a statement which is used to break (terminate) the loop execution and program’s control reaches to the next statement written after the loop body.
§  It brings control out of the loop
Syntax:


for i in range(1,10):
    if i==5:
        break
    print(i)
print('Welcome Out of loop')
Output:
1
2                                                           
3
4
Welcome Out of loop
Explanation
§  In this program, we iterate number from 1 to 10 through range and We check if the number is "i", upon which we break from the loop. Hence, we see in our output that all the number up till "i" gets printed. After that, the loop terminates.

Write a Python program to enter any string Print all the letters that are present before the vowel in given word
word=input('enter any word')
for w in word:
    if w in 'aeiou':
        break;
    print(w,end='')
Output:
enter any wordpython
pyth

The continue Statement In Python:
§  The continue statement is used to skip the rest of the code inside a loop for the current iteration only.
§  The continue statement rejects all the remaining statements in the current iteration of the loop and moves the control back to the top of the loop.
§  Syntax:








Example:
for i in range(1,10):
    if i==5:
        continue
    print(i,end='')
print('\nwelcome outside loop!.')
Output:
12346789
welcome outside loop!.


Explanation
§  In this program, we iterate number from 1 to 10 through range and We check if the number is "i", upon which we break from the loop. Hence, we see in our output that all the number up till "i" gets printed. After that, the loop terminates.


Write a Python program to enter any string Print all the letters that are present before the vowel in given word
word=input('enter word')
word=word.lower()
for w in word:
    if w in 'aeiou':
        continue
    else:
        print(w,end='')    
Output:
enter wordpython
pythn


author

Author Name

Author Description!

Get Free Email Updates to your Inbox!

Post a Comment

www.CodeNirvana.in

Powered by Blogger.

About

Site Links

Popular Posts

Translate

Total Pageviews