可以在if、switch、while和for语句的控制结构内定义变量,这些变量只能是内部可见
while (int i = get_num()) // 每次迭代时创建并初始化i
cout << i << endl;
i = 0; // 错误,在循环外部无法访问i
练习:找出例子中的问题
while (string::iterator iter != s.end()){/*...*/} // 每次循环则重新定义迭代器,无法起到迭代效果
while (bool statue = find(word)) {/* ... */}
if (!statue) {/*...*/} // statue是在while范围内定义和使用的,外部未定义不能使用