for (int i = 1; i < 4; i++)
{
for (int j = 1; j <= 5; j++)
{
if ((i*j)%5 != 0)
{
Console.Write("{0}\t", i * j);
break;
}
Console.WriteLine();
}
}
Console.WriteLine();
Console.WriteLine("continue");
for (int i = 1; i < 4; i++)
{
for (int j = 1; j <= 5; j++)
{
if ((i * j) % 5 != 0)
{
Console.Write("{0}\t", i * j);
continue;
}
Console.WriteLine();
}
}
Console.ReadLine();
結果是:
1 2 3
continue
1 2 3 4
2 4 6 8
3 6 9 12
Break
1)可以用於switch-case判斷中,用於跳出switch
2)用於在循環中,用於立即跳出(終止)循環
注意:用於循環中時,跳出的是break所在的循環
Continue
用於循環中,程序一旦執行到continue語句,立即結束本次循環,再不會執行continue下面的語句.直接進入下一個循環條件。