判斷
if-else
if(condition)
{}
else
{}
if{condition}
{}
else if(condition)
{}三重(Ternary)運算子
condition ? true action : false action
switch-case
int x = 1;
int y;
int z;
switch(x)
{
case 2-1; // 等同 case 1:
y=2;
break;
case 1+1;
y=3;
break;
case 3:
y=5; // 注意這裡沒有break, 所以假如y=5之後就會繼續執行z=2
case 4:
z=2;
break;
default:
break;
}char[] str;
switch(str)
{
case "Hello":
. . .
case "World":
. . .
}迴圈for 迴圈
for(initializer; termination condition; per-iteration action) { } while迴圈
do
{
. . .
} while(termination condition) foreach 迴圈foreach([index], value; container) { } goto 控制
void main()
{
int x = 1;
repeat: // This is a label.
x += 1;
if(x < 3) goto repeat; // Repeat x+=1 until x is no longer less than 3.
}

沒有留言:
張貼留言