控制语句结构
2013-10-16 16:52
246 查看
if
if (x == 100) cout << "x is 100";
if (x == 100) { cout << "x is "; cout << x; }
if (x == 100) cout << "x is 100";elsecout << "x is not 100";
if (x > 0) cout << "x is positive"; else if (x < 0) cout << "x is negative"; else cout << "x is 0";while
while (n>0) { cout << n << ", "; --n; }do while
do { cout << "Enter number (0 to end): "; cin >> n; cout << "You entered: " << n << "\n"; } while (n != 0);
for (int n=10; n>0; n--) { cout << n << ", "; }
for ( n=0, i=100 ; n!=i ; n++, i-- ) { // whatever here... }break
for (n=10; n>0; n--) { cout << n << ", "; if (n==3) { cout << "countdown aborted!"; break; } }continue
for (int n=10; n>0; n--) { if (n==5) continue; cout << n << ", "; }goto
int main () { int n=10; loop: cout << n << ", "; n--; if (n>0) goto loop; cout << "FIRE!\n"; return 0; }
switch (x) { case 1: cout << "x is 1"; break; case 2: cout << "x is 2"; break; default: cout << "value of x unknown"; }
switch (x) { case 1: case 2: case 3: cout << "x is 1, 2 or 3"; break; default: cout << "x is not 1, 2 nor 3"; }
int x = 10;
int y=0;
switch (x) { case 10:
y=30; default: y+=20; }
//y == 50
相关文章推荐
- (六)java结构控制语句
- 流程控制语句————If选择结构语句
- 编写控制结构之循环语句
- 使用控制结构——循环语句——WHILE循环
- C++控制结构-条件语句
- 运维之shell篇-----3.循环结构 、 case语句 、 函数及中断控制
- Java编码约定中对下列部分的要求:类、属性、方法、包、文件名、变量、常量、控制结构、语句行、注释
- PL/SQL-3 控制结构语句
- 【PHP学习】控制结构/文件包含语句
- 循环结构 、 函数及中断控制 、 case语句
- Java基础之switch语句、循环结构语句、跳转控制语句
- 编写控制结构之条件分支语句
- Java基础循环结构,以及循环控制语句break,continue,return
- PL/SQL-3 控制结构语句
- (6)javascript的程序控制结构及语句-----(1)条件判断
- 使用控制结构——循环语句——FOR循环
- PL/SQL-3 控制结构语句
- php控制结构语句declare中的tick的详解
- PL/SQL 流程控制语句-条件结构,循环结构
- 嵌套的控制结构、其他控制语句