Equinox Online Help - Language Reference - A to Z

Home

Block ... End Block

Applies to
SyntaxBlock [LabelName]
[Local Variable Declarations]
Statements
[Exit Block LabelName]
[Continue Block LabelName]
End Block [LabelName]

Note that you can use EndBlock instead of End Block
Action[Statement] This construction defines the enclosed statements as an identifiable block. Another part of the method can refer to it using the block's name
ScopeUsable anywhere
Notes

Block statements provide an extremely simple and powerful way to control the flow of a method. You can make all other control-flow constructions using Block statements. There is no hidden test or loop. The argument LabelName defines the name of the block; you can then use LabelName to refer to the block, when required.

Control passes through the Block statement, continues through the statements in the middle and passes through the End Block statement. If the Exit Block statement is encountered, control immediately passes to the line following End Block. If the Continue Block statement is encountered, then control passes back to the start of the block. Note that with both the Exit and Continue clauses, you may omit the keyword Block, if desired. You must still include LabelName, however.

If you use this structure in conjunction with the If and Goto statements, you can construct complicated algorithms in a structured and well-documented manner. As with other control structures, you may nest Block statements.

Note that you may create local variables at the beginning of a block, but you may only use them within the block itself. They may not share names with fields or variables in any other blocks within which they are contained (but they may have the same name as variables in unrelated blocks).

CategoryFlow Control
See Also BreakPressed, Continue, Execute, EnableInput, Exit, For...Next, Goto, If_Then, Repeat_Until, Return, Sleep, Subtable, Switch, While_EndWhile
Example

This example validates a series of field values. Rather than give a lot of (possibly confusing) messages, one for each error, the validation is stopped as soon as one error is detected.

Logical error

| data entry check point: validate items just entered

Block
error = 1

if cost < 0 then
Message "Cost must be > 0", 1
exit Block
end if

if ItemCode = "" and NoItems <> 0 then
Message "You must include a part Number", 1
Exit Block
end if

...

| no errors - complete the processing For this line
error = 0
tax = cost * TaxRate
gross = cost + tax

...
end block

| make the operator re-edit the line If necessary

if error then ChangeObject "LineStart"

The next example sets up three buttons marked A, B and C and then displays an Alert box containing a question and three possible answers. The user's answer is compared with the variable CorrectAnswer. The user is not allowed to press Escape; if that happens the question is repeated.

Block
AlertButtons "A", "B", "C"
Alert question, AnswerA, AnswerB, AnswerC

if SysReply = CorrectAnswer then
StatusLine "Correct"
else if SysReply < 0 then
StatusLine "You must answer the question"
Continue Block
else
| CorrectAnswer is a Number: 1,2, or 3
| convert it To A,B or C using Mid()
| NB the \ is used To Continue statement on Next line
StatusLine "The correct answer was " & \
Mid("ABC", CorrectAnswer, 1)
end if
end block

Equinox Goto statements use named blocks as their destination point. Some authorities on programming style prohibit the use of Goto, but in certain cases, a clearer style can result.

The next example shows how an insurance claim might be evaluated. Such systems have complicated inter-dependent conditions which must eventually lead to one of several possible actions.

If ClaimType = "HOUSE" Then If TotalInsured < ClaimValue Then Goto HivalueClaim Else Goto HouseClaim End If Else If ClaimValue > 5000 Then Goto HivalueClaim Else Goto DefaultClaimProcedure End If Block HouseClaim ... | no more processing For this claim Exit Method End Block Block HivalueClaim ... End Block | "fall through" into the Default Procedure Block DefaultClaimProcedure ... Exit Method End Block

In the final example, two Switch clauses have some common code. A block is used to avoid repetition.

Switch VehicleType
case "FOURWHEELDRIVE"
...
Goto offroad
case "JEEP"
...

block offroad
...
end block
case "SALOON"
...
default
...
end switch