This page has been translated automatically.
UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
FAQ
编程
Fundamentals
Setting Up Development Environment
Usage Examples
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
应用程序接口
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

If-Else语句

如果某种条件为,就执行if 部分的代码。 如果条件为, 就执行else部分的代码。

语法

源代码 (UnigineScript)
if(expression) { 
	// code_if_true
} else { 
	// code_if_false 
}

部分

  • expression为条件。

示例

源代码 (UnigineScript)
int a = 2;
int b = 5;

if(a > b) {
	log.message("true\n");
} else {
	log.message("false\n");
}

// 输出:假

可分别使用ifelse

源代码 (UnigineScript)
int a=2;
if(a == 2) log.message("a is equal to 2\n");

// 结果为: a is equal to 2

注意
请注意如果条件处为一个复杂的布尔型表达式,会按照从左到右的方式对表达式进行求值(短路求值):
源代码 (UnigineScript)
int func(int a) {
	return a;
}

// 仅调用一次(第一次)func()
if(func(0) && func(1)) log.message("true\n");
// 两次调用func()
if(func(1) && func(1)) log.message("true\n");
// 仅调用一次(第一次)func()
if(func(1) || func(1)) log.message("true\n");
// 两次调用func()
if(func(0) || func(1)) log.message("true\n");
最新更新: 2018-06-04
Build: ()