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
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes

Forloop语句

由于循环条件通常为简单的表达式而且循环常常对数字顺序进行迭代,因此才有了 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