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

时间:2014-06-09 00:02:16   收藏:0   阅读:566

常见的编程错误:

错误预防技巧:

良好的编程习惯:

C++版本

bubuko.com,布布扣
// Counter-controlled repetition
#include <iostream>

using namespace std;

int main()
{
    int counter = 1; // declare and initialize control variable

    while(counter <=10)     // loop-continuation condition
    {
        cout << counter << " ";
        counter++;
    }   // end while

    cout << endl;   // output a newline
    return 0;   // successful termination
}   // end main
bubuko.com,布布扣

 

python版本

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

@author: Administrator
"""

# Counter-controlled repetition

counter = 1     # declare and initialize control variable

while(counter <=10):
    print counter,
    counter = counter + 1

print    # output a newline
bubuko.com,布布扣

 

 

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

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