您的位置:首页 > 其它

控制语句结构

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: