This page has been translated automatically.
Getting Started
Migrating to UNIGINE 2.0
C++ API Migration
UnigineScript
Core Library
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
Usage Examples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Forloop

Since one often uses simple expressions as loop conditions, and loops often iterate over numerical sequences, there is an accelerated variant of the for loop, which runs 1,5–2 times faster.

Syntax

Source code (UnigineScript)
forloop(initial_instruction; maximum_value; step) { 
	// some_code;
}
				

Parts

  • initial_instruction is executed before the first loop iteration starts.
  • maximum_value is an expression.
  • step is an expression. step can be omitted, it is 1 by default.
Notice
The loop counter of forloop must always increase, so step must be a positive value or you will get stuck in an infinite loop.

Examples

  • Common form:
    Source code (UnigineScript)
    forloop(int i = 0; 10; 2) {
    	log.message("%d ",i);
    }
    
    //the output is: 0 2 4 6 8
  • Reduced form:
    Source code (UnigineScript)
    int stop = 10;
    
    forloop(int i = 0; stop) {
    	log.message("%d ",i);
    }
    
    //the result is: 0 1 2 3 4 5 6 7 8 9
  • Another way to use forloop:
    Source code (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);
    }
    
    //the output is: 0 1 2 3 4
Last update: 2017-07-03
Build: ()