Skip to main content
Version: 17

Cycles

A cycle, or also called a loop, is a programming tool for cyclical code execution. Descript implements the for cycle for this purpose.

For cycle syntax

for [Running variable] [Start value]...[End value]
        // Place for the looped code
end

Syntax explanation

Any code that is put between the for and the end keywords constitutes the body of the for block and will be executed cyclically. The number of cycles is specified by the Start- and End value parameters.

Parameters

Running variable

This variable is of integer type. Its starting value is given by the Start value parameter, and it will increase by 1 in every subsequent loop, until it reaches the value of the End value parameter. The running variable is usually named $i or $n.

Start value

The starting value of the Running variable.

End value

The last value the Running variable will have in the last cycle.

Cycle block specific commands

The following commands are only valid within the body of a for loop:

BREAK

Exits the for loop. In other words, it jumps to the execution of the next line after the end keyword of the current for block.

CONTINUE

Jumps to the next cycle within the for loop, without executing the rest of the for block's body. In other words, it jumps to the first line of the for block with the Running variable increased by 1. If this would increase the Running variable to be more then the End value, then it jumps out of the for block.

Sample code

For loop only:

for $i 1...10

// Place for the looped code

end

Example:

LOAD_SECTION_LIBRARY Sec_ID "HEA 200"      // Load a section into the model

$Mem_prefix=Mem_ID_ // Prefix for creating member IDs

// For cycle
for $i 1...3

CONCAT $Mem_prefix $i Act_Mem_ID

CREATE $Act_Mem_ID Structural_Member "HEA 200"
$i*1000 0 0
$i*1000 0 1000+$i*100

end

Let's look at what happens here step-by-step:

  • First we load a section into the model
  • We create a variable named $Mem_prefix for member ID generation
  • Then we start the for cycle with the Running parameter named $i, Start value of 1 and End value of 3.
    This will run our code 3 times with $i getting the values 1, 2 and 3 assigned to it in each subsequent loop.
  • Within the body of the for loop
    • First we have a CONCAT command, that creates a member ID from the value of the $Mem_prefix variable and the current value of $i and saves it into a variable named $Act_Mem_ID, that will be used in the CREATE command.
    • Then we have a CREATE command that will create a structural member
    • The first line immediately after the CREATE command is the member's starting point's (x, y, z) coordinates, where x = $i * 1000
    • The second line immediately after the starting point's coordinates is the endpoint's (x, y, z) coordinates, where x is the same as in case of the starting point, and z = 1000 + $i * 100
  • After these lines the end keyword closes the body of the for loop

As a result we will have 3 vertical structural members created next to each other, with increasing height: