计数器控制的for循环(C++/python版)

时间:2014-06-08 23:08:55   收藏:0   阅读:338

常见的编程错误:

 

良好的编程习惯:

 

可移植性提示:

 

软件工程知识:

错误预防技巧:

C++版本

bubuko.com,布布扣
// Counter-controlled repetition with the for statement

#include <iostream>

using std::cout;
using std::endl;

int main()
{
    // for statement header includes initialization
    // loop-continuation condition and increment
    for( int counter = 1; counter <= 10; counter++ )
        cout << counter << " ";

    cout << endl;   // output a newline

    return 0;       // indicate successful termination
}   // end main
bubuko.com,布布扣

python版本

bubuko.com,布布扣
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 07 22:25:06 2014

@author: Administrator
"""

for counter in range(1,11):
    print counter,
    
print
bubuko.com,布布扣

 

计数器控制的for循环(C++/python版),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!