When working with Uniface 10.4, developers often encounter various control flow statements that help manage program execution. Today, let's dive deep into one of the more traditional control structures: the goto
statement! ๐
Note: This article is based on the official Uniface documentation 10.4, and I had some assistance from AI in organizing this content.
๐ฏ What is the goto Statement?
The goto
statement in Uniface ProcScript allows you to branch unconditionally to a specified label within your current ProcScript module. It's a simple yet powerful tool for controlling program flow.
๐ Syntax
goto Label
๐ง Parameters
Parameter | Data Type | Description |
---|---|---|
Label |
String | Label of a statement in the current ProcScript module |
๐ก Key Features
- โ Allowed in all component types
- ๐ No return values
- ๐ท๏ธ Labels must end with a colon (:)
- โ ๏ธ Cannot be used inside try, catch, or finally blocks
๐ ๏ธ Practical Example
Here's a real-world example that demonstrates how to use goto
for processing records. This example deletes the first 1001 records and then exits:
operation exec
$1 = 0
retrieve
start: ; the label ends with a colon (:)
if ($1 = 1001)
store
exit
else
remocc
$1 = $1 + 1
endif
goto start ; but no colon is used in the goto line
end; exec
๐ Code Breakdown
- Initialize counter:
$1 = 0
- Start processing:
retrieve
- Label definition:
start:
(note the colon) - Condition check: Stop after 1001 records
- Record removal:
remocc
- Jump back:
goto start
(no colon needed)
โก Best Practices
๐ญ Pro Tip: While goto
works perfectly fine, Uniface recommends using more structured approaches like while
or repeat
statements for better code readability and maintainability.
๐จ Important Limitations
โ ๏ธ Warning: Neither the goto
statement nor its labels are allowed inside try
, catch
, or finally
blocks. Keep this in mind when handling exceptions!
๐ฏ When to Use goto
The goto
statement is particularly useful for:
- ๐ Transaction processing scenarios
- ๐ Batch record operations
- ๐ฎ Simple state machine implementations
- ๐ง Legacy code maintenance
๐ Conclusion
The goto
statement in Uniface 10.4 provides a straightforward way to control program flow, especially useful in transaction processing scenarios. While modern programming favors structured approaches, understanding goto
remains valuable for maintaining existing codebases and specific use cases where it shines! โจ
Happy coding with Uniface! ๐
Top comments (0)