Learnbay.Datascience (1) - PowerPoint PPT Presentation

About This Presentation
Title:

Learnbay.Datascience (1)

Description:

In python, we have loop control statements They can be used to alter or control the loop  execution flow depending on specified conditions. We have 3 transfer statements in Python namely break, continue and pass. All the 3 statements are discussed in detail along with the example and the flow chart for better understanding. To learn more about transfer statements , IBM certified data science courses or online data science courses , Visit: or Follow us on our social media platforms mentioned in the above document. – PowerPoint PPT presentation

Number of Views:12

less

Transcript and Presenter's Notes

Title: Learnbay.Datascience (1)


1
(No Transcript)
2
Transfer Statements
  • In python, loop statements or transfer statements
     allows you to run the code block repeatedly. But
     sometimes you will need to exit the loop entirel
    y or skip the particular section of the loop when
     it reaches the specified condition. It can be acc
    omplished using the loop control mechanism. 
  • In python, we have loop control statements can be
     used to alter or control the loop execution flow 
    depending on specified conditions.

3
  • The loop control statements supported by Python
    are
  • break statementTerminates the loop statement
    and transfers execution to the statement
    immediately following the loop.
  • continue statementCauses the loop to skip the
    remainder of its body and immediately retest its
    condition prior to reiterating.
  • pass statementThe pass statement in Python is
    used when a statement is required syntactically
    but you do not want any command or code to
    execute.

4
Break statement
  • The break statement terminates the loop
    containing it. Control of the program flows to
    the statement immediately after the body of the
    loop.
  • The break statement can be used in
    both while and for loops.
  • If you are using nested loops, the break
    statement stops the execution of the innermost
    loop and start executing the next line of code
    after the block.
  • Syntaxbreak

5
Flow Chart
6
Example
  • for i in range(10)  if i  7         break
        else         print(i)
  • O/P0 12 3 45 6

7
Continue Statement
  • It returns the control to the beginning of the
    while loop.
  • 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.
  • Continue statement forces the loop to continue or
    execute the next iteration. When the continue
    statement is executed in the loop, the code
    inside the loop following the continue statement
    will be skipped and the next iteration of the
    loop will begin.
  • The continue statement can be used in
    both while and for loops.
  • Syntax continue

8
Flow diagram
9
Example
  • for i in range(10)    if i 7 or i  4
  •          continue    else
  •          print(i)
  • O/P0 1 2 3 5 6 8 9

10
Pass statement
  • As the name suggests, the pass statement actually 
    doesn't do anything. The Python Pass statement is
     used when a statement is required syntactically, 
    but you do not want any command or code to be exe
    cuted. 
  • It's like zero operation, because nothing happens 
    when it's executed. 
  • Pass statement can also be used to write empty lo
    ops. Pass is also used for empty control statement
    s, functions and classes.
  • It is used to write boilerplate code.
  • Syntax pass

11
Flow chart
12
Example-pass boilerplate code
  • for i in range(10)    passdef f1()
  •      pass
  •  var  0while var lt 100     pass
  •    var  1print(i)
  • O/P9

13
Thanks for watching!
  • Follow us for more such content on our social
    media platforms
  • Facebook Learnbay
  • Instagram Learnbay_datascience
  • Twitter Learnbay1
  • LiknkedIn Learnbay
  • Youtube (Tutorials) https//www.youtube.com/chann
    el/UC-ntE_GnjjiUuKYqih9ENYA
Write a Comment
User Comments (0)
About PowerShow.com