內容
控制程式的流程和執行步驟,以中括號 { } 控制範圍
{ }
if (x == 100)
cout << "x is 100";
{
cout << "x is ";
cout << x;
}
else
cout << "x is not 100";
if (x > 0)
cout << "x is positive";
else if (x < 0)
cout << "x is negative";
cout << "x is 0";
while (n>0) {
cout << n << ", ";
--n;
do {
cout << "Enter number (0 to end): ";
cin >> n;
cout << "You entered: " << n << "\n";
} while (n != 0);
for (int n=10; n>0; n--) {
{ ... }
break;
continue;
xxx
:
int n=10;
loop:
n--;
if (n>0) goto loop;
cout << "FIRE!\n";
cstdlib
exit(0);
switch (x) {
case 1:
cout << "x is 1";
case 2:
cout << "x is 2";
default:
cout << "value of x unknown";
case