4-2 编程练习
本节编程练习不计算学习进度,请电脑登录imooc.com操作

编程练习

while 循环通常有一个计数变量,循环开始前声明并初始化这个变量;需要有循环条件,当条件为 true 时,执行一次循环体,当条件为 false 时,结束循环。

循环体里面需要有技术变量的自加语句,否则循环可能无法退出(即“死循环”)。

任务

这段程序循环打印 5 次“加油!”,请完善行 ①-③ 的代码。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace Test
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int x;//循环计数变量
  12. //行① 请填写计数变量的初始化语句
  13.  
  14.  
  15. while ( )//行② 请填写循环条件
  16. {
  17. Console.Write("加油!");
  18. //行③ 请填写计数变量的自加语句
  19.  
  20. }
  21. }
  22. }
  23. }
下一节