THE WHILE STATEMENT
while (condition) {
statement
}
运算符号
a += b means a = a+b
++a means a = a+1
while的一个练习
while中是“有if”的,如果不满足就不会执行。
比大小可以在while的条件里(不用单独写if大的存在c,小的存在d。。。)
Exercise 1.11:
Write a program that prompts the user for two integers. Print each
number in the range specified by those two integers.
for 循环
for loop = header + body;
header = (an initial statement; a condition; an expression)
FOR 与 WHILE 的区别
while循环中,这个控制循环次数的变量val 是可以再while执行结束后继续使用;
但for循环中,val这个变量是含在for里面的,for结束它就结束了。