Python break, continue and pass Statements

Python offers a break and continues to control such cases and has good control over your circle.This training will address the breaking of sentence, continue to make Python.

Introduction:

Using circles and circuits in Python will allow you to work on tasks and benefits.
But sometimes external factors can affect the way the program works. When this happens, you may want to make a program that you have finished the drawer, jumping from the front door before continuing to ignore the external issues. You can do these steps and breakthroughs, breaking and forwarding.

What is the use of Break and continue in Python?

Python, Break and continue of the declaration can change the usual cycle.
Loops to repeat the border number until the test scan is false, but we always want to end the current or even the whole circle without judging the test scores.
Holidays and sentences are still in use in this case.

The Break Statement:

Python's breach of the sentence has ended in the velocity of the current and subsequently restarting judgment, with the exception of traditional breed found in C.
The maximum use is determined when some conditions are outdoors, which need to be removed immediately. The text can be used to break the cycle time.
For example:
#!/usr/bin/python

for letter in 'Python':     # First Example

   if letter == 'h':

      break

   print 'Current Letter :', letter

var = 10                    # Second Example

while var > 0:             

   print 'Current variable value :', var

   var = var -1

   if var == 5:

         break

print "Good bye!"
This will produce the following results:
Current Letter : P

Current Letter : y

Current Letter : t

Current variable value : 10

Current variable value : 9

Current variable value : 8

Current variable value : 7

Current variable value : 6

Good bye!

The continue statement:

Python's text repeats the control of the start-up period. It repeatedly denies all the statements contained in the repeated tactile tactics and control of the control of the cycle.
The text occurred to be used during the cycle.
For example:
#!/usr/bin/python

for letter in 'Python':     # First Example

   if letter == 'h':

      continue

   print 'Current Letter :', letter

var = 10                    # Second Example

while var > 0:             

   var = var -1

   if var == 5:

      continue

   print 'Current variable value :', var

print "Good bye!"
This will produce the following results:
Current Letter : P

Current Letter : y

Current Letter : t

Current Letter : o

Current Letter : n

Current variable value : 10

Current variable value : 9

Current variable value : 8

Current variable value : 7

Current variable value : 6

Current variable value : 4

Current variable value : 3

Current variable value : 2

Current variable value : 1

Good bye!

The Else Statement used with Loops:

• If other proofs are used in the circle, the other statement will be applied to the list of the lists.
• If there are other leaflets used during the cycle, this statement will be enforced when the other terms are false.
For example:
The following examples illustrate the combination of other indicators to obtain the basic numbers 10 to 20.
#!/usr/bin/python

for num in range(10,20):  #to iterate between 10 to 20

   for i in range(2,num): #to iterate on the factors of the number

      if num%i == 0:      #to determine the first factor

         j=num/i #to calculate the second factor

         print '%d equals %d * %d' % (num,i,j)

         break #to move to the next number, the #first FOR

   else:        # else part of the loop

      print num, 'is a prime number'
This will produce the following results:
10 equals 2 * 5

11 is a prime number

12 equals 2 * 6

13 is a prime number

14 equals 2 * 7

15 equals 3 * 5

16 equals 2 * 8

17 is a prime number

18 equals 2 * 9

19 is a prime number
So you can do any other appearance of loop while ringing.

The Pass Statement:

Written statement is passed on to Python as used when the evidence is required in the same way, but you do not want to order all orders or sounds.
Guidelines for use are invalid; nothing happened if done. It also benefits from areas where the code is likely to be, although not written (for example, lists, for example):
For example:
 #!/usr/bin/python

for letter in 'Python':

   if letter == 'h':

      pass

      print 'This is pass block'

   print 'Current Letter :', letter

print "Good bye!"
This will produce the following results:
 Current Letter : P

Current Letter : y

Current Letter : t

This is pass block

Current Letter : h

Current Letter : o

Current Letter : n

Good bye!

The law did not carry any evidence or letter in the case of 'h'. The last statement is useful if you make a block of code, but there is no need.
After that you can delete the instructions in the block, but leave the normal block, so that it does not interfere with other parts of the number.

Comments

  1. And indeed, Iam just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I have had.
    oracle training in chennai
    |oracle training in chennai | best oracle training in chennai | oracle Training Institute in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Python – Functions

What is Django in python?

What do you learn about Python?