zoukankan      html  css  js  c++  java
  • C++猿的Python笔记02控制流

    注意冒号  

      if else  

    if ... :

    缩进

    else :

    缩进 

    if guess == number:
        
    print 'Congratulations, you guessed it.' # New block starts here
        running = False
    elif guess < number:
        
    print 'No, it is a little higher than that' # Another block
        # You can do whatever you want in a block ...
    else:
        
    print 'No, it is a little lower than that'
        
    # you must have guess > number to reach here

     

      switch  

    没有switch,用if..: elif ..: else: 代替

      while   

    while xx:

    缩进 

    else:

    缩进 

    while done == False:
        i 
    = i+1;
        
    print 'frame', i
    else:
        
    print 'The while loop is over.'

      

      for  

    for element in arrays:

    缩进

    else:

    缩进 

    for i in range(15):
    print i
    else:

    print 'The for loop is over'  


      break   

    终止循环。

    注意:如果你从for或while循环中终止 ,任何对应的循环else块将不执行。 

      continue   

    逃过本次循环后面的语句,进入下一轮循环。

    注意:continue语句对于for循环也有效。 

  • 相关阅读:
    ES5新特性:理解 Array 中增强的 9 个 API
    ios
    Jquery异步 Deferred Object
    ES5中新增的Array方法详细说明
    Chart
    Angular常用语句
    vticker.js--垂直滚动插件
    <css系列>之css--float总结
    理解boot.img与静态分析Android/linux内核
    理解竞争条件( Race condition)漏洞
  • 原文地址:https://www.cnblogs.com/mumuliang/p/2130977.html
Copyright © 2011-2022 走看看