Java Reference
In-Depth Information
int inputMsgSize = errorMsgs[x].msgSize;
if (inputMsgSize == 0) {
// Exit the loop immediately. x will point to this element.
break; // The break statement causes the loop to
// exit. The statement after the loop's
// ending brace will be the next statement
// executed.
}
x++; // Increment the loop variable.
continue; // Continue the loop. This statement is not required
// but is shown here to show how continue might be
// used. The continue statement causes the loop to
// proceed with the next iteration.
}
// The loop has completed.
// At this point either you have found an element that contains a 0 size,
// or you have examined all of the objects in ErrorMsgs. Test x to see if
// you tested all of the items in ErrorMsgs (that is, is x equal to
// ARRAY_SIZE?).
if (x != ARRAY_SIZE) {
// You have an ErrorMsg with a 0 size !
...
}
else {
// You have none. The array was exhausted
...
}
As in any programming language, Java loops are often a mechanism to manip-
ulate an array of similar items. I discussed arrays in Chapter 4, and I will discuss the
more powerful collection processing in detail in Chapter 11, but a word of review
about arrays and array processing in Java seems appropriate at this time.
In COBOL, subscripts for arrays (that is, items that OCCUR x TIMES) start
with 1. That means the first item in an array is referenced as ITEM (1), and the last
item is referenced as ITEM (x).
For example, the statement:
01 MY-ITEMS PIC X(2) OCCURS 10 TIMES.
defines an array called MY-ITEMS. Each item in the array is 2 bytes, and there are
10 items in the array. Any subscript in the range of 1 through 10 is valid:
Search WWH ::




Custom Search