while loop [Python] 05_Python basis of

Three processes 1. Introduction program

  • Order  - from top to bottom , the order of execution
  • Branch  - The conditions of determination, the branch decision code
  • Circulation  - make specific code is executed

2.while basic grammar

while condition (determination counter reaches the target number of times):

  When the conditions are met, to do 1

  When the conditions are met, do 2

  ……

  Process conditions (counter + 1)

NOTE: while statement and the indented portion is a complete block of code

3. assignment operator

4.break 和 continue

  • break when a certain condition is satisfied, the loop is exited , the code is not executed subsequently repeated
  • continue when a certain condition is satisfied, no loop is exited , the code does not perform subsequent iterations

Note: BREAK and continue for the current cycle where the only valid

5. nested loop

while Condition 1:

  1 when the condition is met, do 1

  1 when the condition is met, do 2

  ……

  while Condition 2:

    When the condition 2 is met, do 1

    When the condition 2 is met, do 2

    ……

    Process conditions (counter + 1)

  Process conditions (counter + 1)

6. escape character

  • \ t   output console in a tab to assist in maintaining vertical alignment of the text when the output
  • \ n     In the console output a newline

Escape character table:

 

7. comprehensive training multiplication table

1 row = 1
2 while row <= 9:
3     col = 1
4     while col <= row:
5         print("%d X %d = %d" % (col, row, row * col), end="\t")
6         col += 1
7     print("")
8     row += 1

 Output:

Guess you like

Origin www.cnblogs.com/dujinyang/p/11258080.html