This page has been translated automatically.
Video Tutorials
Interface
Essentials
Advanced
Полезные советы
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 Tools
GUI
Double Precision Coordinates
API
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
Внимание! Эта версия документация УСТАРЕЛА, поскольку относится к более ранней версии SDK! Пожалуйста, переключитесь на самую актуальную документацию для последней версии SDK.
Внимание! Эта версия документации описывает устаревшую версию SDK, которая больше не поддерживается! Пожалуйста, обновитесь до последней версии SDK.

Foreach

Warning
The scope of applications for UnigineScript is limited to implementing materials-related logic (material expressions, scriptable materials, brush materials). Do not use UnigineScript as a language for application logic, please consider C#/C++ instead, as these APIs are the preferred ones. Availability of new Engine features in UnigineScipt (beyond its scope of applications) is not guaranteed, as the current level of support assumes only fixing critical issues.

The foreach construct is used to iterate over vectors and maps.

Syntax

Source code (UnigineScript)
foreach(value_variable; container; loop_increment) { 
	// some_code;
}

Parts

  • value_variable is the value of the current container element.
  • container is a vector or a map.
  • loop_increment is executed at the end of each iteration.

On each iteration, the value of the current element is assigned to value_variable and the internal container cursor is moved to point at the next container element. The type of value_variable doesn't matter. loop_increment is optional.

Modifications of elements inside the foreach block affect the container; synchronization occurs at the end of each iteration.

Examples

  • For each vector element:
    Source code (UnigineScript)
    int vector[4] = ( 1, vec3(1,2,3), -7.2e-2, "end" );
    foreach(int i; vector) {
    	log.message("%s\n",typeinfo(i));
    }
    The example displays the following:
    Output
    int: 1
    vec3: 1 2 3
    float: -0.072
    string: "end"
  • For each map element:
    Source code (UnigineScript)
    int map[] = ( 1 : "begin", 2 : 2, 3 : "end" );
    foreach(int i; map) {
    	log.message("%s\n",typeinfo(i));
    }
    The result is:
    Output
    string: "begin"
    int: 2
    string: "end"
  • Increment:
    Source code (UnigineScript)
    foreach(int i, j = 0; vector; j++) {
    	log.message("%d: %s\n",j,typeinfo(i));
    }
    The output is:
    Output
    0: int: 1
    1: vec3: 1 2 3
    2: float: -0.072
    3: string: "end"
Last update: 31.07.2020
Build: ()