This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
专业(SIM)
UnigineEditor
界面概述
资源工作流程
版本控制
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
Rebuilding the Engine Tools
GUI
双精度坐标
应用程序接口
Animations-Related Classes
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
VR-Related Classes
创建内容
内容优化
材质
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Tutorials

Forloop语句

警告
UnigineScript的应用范围仅限于实现与材质相关的逻辑(材质表达式,可编写脚本的材质,画笔材质)。 不要将UnigineScript用作应用程序逻辑的语言,请改用C#/C++,因为这些API是首选的。 无法保证UnigineScript中新引擎功能的可用性(超出其应用范围),因为当前的支持级别仅假设已解决关键问题。

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