UnigineEditor
Interface Overview
Assets Workflow
Settings and Preferences
Working With Projects
Adjusting Node Parameters
Setting Up Materials
Setting Up Properties
Landscape Tool
Using Editor Tools for Specific Tasks
Extending Editor Functionality
编程
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
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes

Forloop语句

警告
UnigineScript已过时,将在以后的版本中删除。请考虑切换到C#/ C ++,因为这些API是首选。无法保证UnigineScipt中新引擎功能的可用性,因为当前的支持水平仅假设解决关键问题。

由于循环条件通常为简单的表达式而且循环常常对数字顺序进行迭代,因此才有了 for 循环的改进变体,其运行速度比for循环快1,5–2倍。

语法#

源代码 (UnigineScript)
forloop(initial_instruction; maximum_value; step) { 
	// some_code;
}

部分#

  • 在开始第一个循环迭代之前执行initial_instruction
  • maximum_value为一个表达式。
  • step为一个表达式。 step可省略,默认值为 1
注意
forloop的循环计数器会一直增加,因此step必须为正数值否则会陷入无限循环。

示例#

  • 普通形式:
    源代码 (UnigineScript)
    forloop(int i = 0; 10; 2) {
    	log.message("%d ",i);
    }
    
    //输出为: 0 2 4 6 8
  • 简化型:
    源代码 (UnigineScript)
    int stop = 10;
    
    forloop(int i = 0; stop) {
    	log.message("%d ",i);
    }
    
    //结果为:0 1 2 3 4 5 6 7 8 9
  • 另一种使用forloop的方式:
    源代码 (UnigineScript)
    class Foo {
    	int a = 10;
    	int foo() { return a; }
    };
    
    int a = 10;
    Foo f = new Foo();
    
    forloop(int i = 0; f.foo() + 1) {
    	log.message("%d ",i);
    }
    
    //输出为: 0 1 2 3 4
最新更新: 2017-07-03