什么是 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