411 REFERENCE · Wikibooks
Application Development with Harbour/Control Structures
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Loops
WHILE
[DO] WHILE condition
...
[LOOP]
[EXIT]
END[DO]
FOR
FOR var := init_exp TO end_expr [STEP step_expr]
...
[LOOP]
[EXIT]
NEXT
FOR EACH
FOR EACH var IN collection_expr
...
[HB_EnumIndex()]
[LOOP]
[EXIT]
NEXT
IF
IF condition
...
[ELSEIF condition]
...
[ELSE]
...
END[IF]
The IF control structure is useful for validating data. Example:
PROCEDURE Main()
LOCAL nAge := 0
INPUT "Age: " TO nAge
IF nAge > 18
? "Valid age"
ELSE IF nAge > 0
? "Too young!"
ELSE
? "Error: impossible age"
ENDIF
RETURN
SWITCH
SWITCH condition
CASE literal_expr
...
[EXIT]
[CASE literal_expr]
...
[EXIT]
[DEFAULT]
...
END
BEGIN SEQUENCE
BEGIN SEQUENCE
...
[BREAK]
[Break([expression])]
[RECOVER [USING var]]
...
END [SEQUENCE]