1.4.1 while语句

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qit1314/article/details/89925656

书中页数:P10
代码名称:whilecount.cc

    #include <iostream>
    
    int main()
    {
        int sum = 0, val = 1;
        // keep executing the while as long as val is less than or equal to 10
        while (val <= 10) {
            sum += val;  // assigns sum + val to sum
            ++val;       // add 1 to val
        }
        std::cout << "Sum of 1 to 10 inclusive is " 
                  << sum << std::endl;
    
    	return 0;
    }

猜你喜欢

转载自blog.csdn.net/qit1314/article/details/89925656