| Table of Contents / Control | Operators |
for — Starts a loop block that is executed for a fixed number of iterations.
The for statement starts a loop block that is executed for a fixed number of iterations. The for block ends at the corresponding endfor statement.
The number of iterations is defined by the Start value, the End value, and the incrementation value Step. 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 for 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 for loop within the loop body will have no influence in the number of iterations.
For every iteration the loop variable Index 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 Index variable is calculated according to that formula, i.e., assignments to the Index 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 Step is positive, the for loop is executed as long as the Index variable is smaller than or equal to the End parameter. If the incrementation value Step is negative, the for loop is executed as long as the Index variable is greater than or equal to the End parameter.
The passed loop parameters may be of type integer or real. If all input values are of type integer the Index variable will also be of type integer. In all other cases the Index variable will be of type real.
If the for loop is stopped, e.g., by a stop statement or by pressing the Stop button, and if the PC is placed manually by the user, the for loop is continued at the current iteration as long as the PC remains within the for body or is set to the endfor statement. If the PC is set on the for statement and executed again, the loop is reinitialized and will restart at the beginning.
Increment value for the loop variable.
Default value: 1
Loop variable.
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')
If the values of the specified parameters are correct for (as operator) returns 2 (H_MSG_TRUE). Otherwise an exception is raised and an error code returned.
repeat, break, continue, if, elseif, else
Foundation
| Table of Contents / Control | Operators |
| HALCON Reference Manual 10.0.2 | Copyright © 1996-2011 MVTec Software GmbH |