什麼是 C# 中的控制語句?
在 C# 中,程式控制流的流程 由控制語句指定。其中包括以下內容 −
if 語句
if 語句由布林表示式後跟一條或多條語句組成。
以下是語法 −
if(boolean_expression) {
/* statement(s) will execute if the boolean expression is true */
}if-else 語句
if 語句後面可以跟一個可選的 else 語句,當布林表示式為假時執行此語句。
以下是語法 −
if(boolean_expression) {
/* statement(s) will execute if the boolean expression is true */
} else {
/* statement(s) will execute if the boolean expression is false */
}for 迴圈
重複執行一系列語句多次,並縮寫管理迴圈變數的程式碼。
以下是語法 −
for ( init; condition; increment ) {
statement(s);
}while 迴圈
不斷重複一條語句或一組語句,直到給定條件為真。在執行迴圈主體之前,它將測試條件。
以下是語法 −
while(condition) {
statement(s);
}do…while 迴圈
類似於 while 語句,不同之處在於它在迴圈體末尾測試條件。
以下是語法 −
do {
statement(s);
} while( condition );
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP