SEARCH
Serial Search
| COBOL | JAVA |
|---|---|
| SEARCH |
for (; <index> <= <occurs>; <index> += 1) { if (<condition>) { <code>; } } |
Syntax
for (; <index> <= <occurs>; <index> += 1) {
if (<condition1>) {
<code1>;
}
[if (<condition2>) {
<code2>;
}]
[ ... ]
}Parameters
<index>
The index variable of the table or VARYING clause variable.
<occurs>
The value of the occurs clause of the table.
<condition1..N>
The conditional expressions for the search.
<code1..N>
The imperative statements to be executed if the condition is met.
| Ending code |
|---|
| The code should always end with a break, goto, return or throw statement. |
Examples
| COBOL | Java |
|---|---|
|
|
|
|
Binary Search
| COBOL | JAVA |
|---|---|
| SEARCH ALL |
for (<index> = 1; <index> <= <occurs>; <index> += 1) { if (<condition>) { <code>; } } |
Syntax
for (<index> = 1; <index> <= <occurs>; <index> += 1) {
if (<condition1>) {
<code1>;
}
[if (<condition2>) {
<code2>;
}]
[ ... ]
}Parameters
<index>
The index variable of the table or VARYING clause variable.
<occurs>
The value of the occurs clause of the table.
<condition1..N>
The conditional expressions for the search.
<code1..N>
The imperative statements to be executed if the condition is met.
| Ending code |
|---|
| The code should always end with a break, goto, return or throw statement. |
Examples
| COBOL | Java |
|---|---|
|
|
|
|
Binary Or Serial Search with AT END
| COBOL | JAVA |
|---|---|
| SEARCH [ALL] ... AT END |
for ([<index> = 1]; <index> <= <occurs+1>; <index> += 1) { if (<index> > <occurs>) { <code_at_end>; } if (<condition>) { <code>; } } |
Syntax
for ([<index> = 1]; <index> <= <occurs+1>; <index> += 1) {
if (<index> > <occurs>) {
<code_at_end>;
}
if (<condition1>) {
<code1>;
}
[if (<condition2>) {
<code2>;
}]
[ ... ]
}Parameters
<index>
The index variable of the table or VARYING clause variable.
<occurs+1>
The value of the occurs clause of the table plus one.
<occurs>
The value of the occurs clause of the table.
<code_at_end>
The imperative statements to be executed at the end of the search.
<condition1..N>
The conditional expressions for the search.
<code1..N>
The imperative statements to be executed if the condition is met.
| Ending code |
|---|
| The code should always end with a break, goto, return or throw statement. |
Examples
| COBOL | Java |
|---|---|
|
|
|
|
