Francais

Francais


Home


Products


Download


Tutorials

    Python Section
  • Python Quick Reference

  • Web Ring/Links


    Contact

    Loop management

    There are 3 commands to control the execution of a loop. Each one applies to the closest indented loop.

    continue

    Tells to the interpreter the use the next value without reach the end of the loop.

    break

    Cancel immediately the loop execution.

    else

    Identify a block of instructions executes when the loop execution is completed. Expect, if the command break have been used to stop it.

    Examples :
    break continue else
    >>> A=0
    >>> while A<5
    …      A+=1
    …      if A==3 : break
    …      print A

    1
    2
    >>> A=0
    >>> while A<5
    …    A+=1
    …     if A==3 : continue
    …    print A
    …   
    1
    2
    4
    5
    >>> A=0
    >>> while A<5
    …      A+=1
    …      print A
    …    else :
    …      print A*2

    1
    2
    3
    4
    5
    10
    Remark: in the continue example, if the line "A+=1" where put after the line "if A==3 : continue ", the loop will never finish, because the variable A will never incremented anymore.

    Special Commands

    pass

    This command does nothing; it uses only when the syntax needs a command for a non-already existing code.

    Example :
    >>>if a<10 :
    …      pass                # développement du code pour a<10 sera fait plus tard
    …   else:
    …    print "a>=10"



    Previous Page
    9/13

    Next Page