HALCON Reference Manual 10.0.2
Table of Contents / Control ClassesClassesClasses | | | Operators

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

Page not available for the currently selected syntax (programming language).

forforforForFor (Operator)

Name

forforforForFor — Starts a loop block that is executed for a fixed number of iterations.

Signature

for( : : Start, End, Step : Index)

Herror for(const Hlong Start, const Hlong End, const Hlong Step, Hlong* Index)

Herror T_for(const Htuple Start, const Htuple End, const Htuple Step, Htuple* Index)

Herror for(const HTuple& Start, const HTuple& End, const HTuple& Step, Hlong* Index)

void HOperatorSetX.For(
[in] VARIANT Start, [in] VARIANT End, [in] VARIANT Step, [out] VARIANT* Index)

static void HOperatorSet.For(HTuple start, HTuple end, HTuple step, out HTuple index)

Description

The forforforForFor statement starts a loop block that is executed for a fixed number of iterations. The forforforForFor block ends at the corresponding endforendforendforEndforEndfor statement.

The number of iterations is defined by the StartStartStartStartstart value, the EndEndEndEndend value, and the incrementation value StepStepStepStepstep. All of these parameters can be initialized with expressions or variables instead of constant values. Please note that the loop parameters are evaluated only once, namely, immediatly before the forforforForFor loop is entered. They are not re-evaluated after the iterations, i.e., any modifications of variables that are used for the initialization of the forforforForFor loop within the loop body will have no influence in the number of iterations.

For every iteration the loop variable IndexIndexIndexIndexindex is set to the current iteration value, that is:

  Index := Start + count * Step

with the internal iteration counter count. Please note that before every iteration the IndexIndexIndexIndexindex variable is calculated according to that formula, i.e., assignments to the IndexIndexIndexIndexindex variable within the body of the loop are lost for the next iteration and will have no influence on the number of iterations at all.

If the incrementation value StepStepStepStepstep is positive, the forforforForFor loop is executed as long as the IndexIndexIndexIndexindex variable is smaller than or equal to the EndEndEndEndend parameter. If the incrementation value StepStepStepStepstep is negative, the forforforForFor loop is executed as long as the IndexIndexIndexIndexindex variable is greater than or equal to the EndEndEndEndend parameter.

The passed loop parameters may be of type integer or real. If all input values are of type integer the IndexIndexIndexIndexindex variable will also be of type integer. In all other cases the IndexIndexIndexIndexindex variable will be of type real.

If the forforforForFor loop is stopped, e.g., by a stopstopstopStopStop statement or by pressing the Stop button, and if the PC is placed manually by the user, the forforforForFor loop is continued at the current iteration as long as the PC remains within the forforforForFor body or is set to the endforendforendforEndforEndfor statement. If the PC is set on the forforforForFor statement and executed again, the loop is reinitialized and will restart at the beginning.

Parameters

StartStartStartStartstart (input_control)  number HTupleHTupleVARIANTHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double) (Hlong / double)

Start value for the loop variable.

Default value: 1

EndEndEndEndend (input_control)  number HTupleHTupleVARIANTHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double) (Hlong / double)

End value for the loop variable.

Default value: 5

StepStepStepStepstep (input_control)  number HTupleHTupleVARIANTHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double) (Hlong / double)

Increment value for the loop variable.

Default value: 1

IndexIndexIndexIndexindex (output_control)  number HTupleHTupleVARIANTHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double) (Hlong / double)

Loop variable.

Example (HDevelop)

dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 728, 512, 'black', WindowID)
read_image (Bond, 'die3')
dev_display (Bond)
stop ()
threshold (Bond, Bright, 100, 255)
shape_trans (Bright, Die, 'rectangle2')
dev_set_color ('green')
dev_set_line_width (3)
dev_set_draw ('margin')
dev_display (Die)
stop ()
reduce_domain (Bond, Die, DieGrey)
threshold (DieGrey, Wires, 0, 50)
fill_up_shape (Wires, WiresFilled, 'area', 1, 100)
dev_display (Bond)
dev_set_draw ('fill')
dev_set_color ('red')
dev_display (WiresFilled)
stop ()
opening_circle (WiresFilled, Balls, 15.5)
dev_set_color ('green')
dev_display (Balls)
stop ()
connection (Balls, SingleBalls)
select_shape (SingleBalls, IntermediateBalls, 'circularity', 'and', 0.85, 1.0)
sort_region (IntermediateBalls, FinalBalls, 'first_point', 'true', 'column')
dev_display (Bond)
dev_set_colored (12)
dev_display (FinalBalls)
stop ()
smallest_circle (FinalBalls, Row, Column, Radius)
NumBalls := |Radius|
Diameter := 2*Radius
meanDiameter := sum(Diameter)/NumBalls
mimDiameter := min(Diameter)
dev_display (Bond)
disp_circle (WindowID, Row, Column, Radius)
dev_set_color ('white')
set_font (WindowID, 'system26')
for i := 1 to NumBalls by 1
  if (fmod(i,2)=1)
    set_tposition (WindowID, Row[i-1]-1.5*Radius[i-1], Column[i-1]-60)
  else
    set_tposition (WindowID, Row[i-1]+2.5*Radius[i-1], Column[i-1]-60)
  endif
  write_string (WindowID, 'Diam: '+Diameter[i-1])
endfor
dev_set_color ('green')
dev_update_window ('on')

Result

If the values of the specified parameters are correct forforforForFor (as operator) returns 2 (H_MSG_TRUE). Otherwise an exception is raised and an error code returned.

Alternatives

whilewhilewhileWhileWhile, untiluntiluntilUntilUntil

See also

repeatrepeatrepeatRepeatRepeat, breakbreakbreakBreakBreak, continuecontinuecontinueContinueContinue, ifififIfIf, elseifelseifelseifElseifElseif, elseelseelseElseElse

Module

Foundation


Table of Contents / Control ClassesClassesClasses | | | Operators
HALCON Reference Manual 10.0.2 Copyright © 1996-2011 MVTec Software GmbH