Here is a strict comparison between control flow constructs in Java and NetRexx.
The DO instruction is used to group togheter chuncks of code. You can exit from a DO group with the LEAVE instruction. You can also protect objects, when the enclosed code executes, with the protect keyword (synchronization), catch exceptions and label the end of the group with a name for easy reading. An empty block or a null instruction must be rendered with NOP.
Java{
|
NetRexxdo |
{}
|
nop |
{
|
do label do_name --... list of instructions end do_name |
synchronized(object) {
|
do protect object --... list of instructions end |
try {
|
do |
The IF instruction is used (as usual) to conditionally execute group of instructions.
Javaif (expression) |
NetRexxif expression then |
if (expression) |
if expression then |
if (expression) {
|
if expression then do |
The LOOP instruction is used to execute repeatedly a block of instructions. You can exit a loop with the LEAVE instruction and repeat it before end with ITERATE. A LOOP block may use all the keywords of DO, such as label, protect, catch and finally. You can build very complex loops with repetitors (to-by-for, over, for and forever) and conditions (while and until).
Javawhile(true) {
|
NetRexxloop forever |
for(int ct = 0; ct < 10; ct++) {
|
loop for 10 |
for(int ct = 0; ct < 10; ct++) {
|
loop ct=0 for 10 |
for(float x=5.1; x<17.2; x+=2.5) {
|
loop x=5.1 to 17.2 by 2.5 |
int ct = 0; |
loop x=20.5 to 2.5 by -2.0 for 4 |
Hashtable hash = new Hashtable(); |
hash=Hashtable -- hash ='' |
while(expression) {
|
loop while expression -- instructions end |
do {
|
loop until expression -- instructions end |
for(float x=0.0; x<9.0; ct+=0.1) {
|
loop x=0.0 to 9.0 by 0.1 |
synchronized(anObject) {
|
loop protect anObject while expression -- instructions catch e=Exception -- instructions end -- -- -- -- |
The SELECT instruction is used to select one of several execution alternatives. The options are listed with the when keyword. If none of the conditions is fulfilled, the code marked with otherwise is executed. You can exit a selection with the LEAVE instruction. A SELECT block may use all the keywords of DO, such as label, protect, catch and finally.
Javaswitch(expression) {
|
NetRexxselect |
if(condition_1) {
|
select |
Exceptions are thrown with the SIGNAL instruction.
Javatry {
|
NetRexxdo |
To stop a program you need to use the EXIT instruction.
Javaif(exit_condition) |
NetRexxif exit_condition then |
[Index] [Previous Chapter] [Next Chapter]