Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping structures in RPG/400

Status
Not open for further replies.

badapplebob

Programmer
May 13, 2003
12
GB
Hello everyone,

Recently I saw some code in the C-Specs that had
DO *HIVAL

some code...

ENDDO

And I was confused as to why and how this would work.

Is it similar to the construct in C where you have

for(;;)
{ if 1=1
break;
}

Any ideas would be much appreciated!!

Thanks,

Bob
 
I believe the *HIVAL Do loop runs till the end of file or last record. I'm still in the learning curve in RPG but I think I remember reading this somewhere. Hvae not used it thoguh

if that is right then it would be the same as saying
Do until %EOF

enddo



_________________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
[/sub]
 
Hi there,

So do you mean that you have to go through the logic cycle to use it. The code was taking 6 numbers from a display file.

Thanks,

Bob
 
Using the DO opcode tells it to execute the code a specified number of times. DO *HIVAL effectively tells it to loop forever. At some point(s) in the code the programmer will have put a LEAVE opcode which exits the DO-loop. This technique is one of my pet hates. It make's it difficult to see why the loop is being performed and if the logic for leaving the loop is wrong it will go on for ever.
Code:
C            DoW        NOT %EOF
C            Eval       x = abcde
.......
C  KeyList   ReadE     File
C            EndDo
seems a lot easier to read than
Code:
C            Do        *HIVAL
C  KeyList   ReadE     File
C            If        %EOF
C            Leave
C            EndIf
C            Eval      x = abcde
......
C            EndDo
I've seen the DO *HIVAL technique described as a "disguised GOTO" and that is probably pretty close to the truth.

PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 

As clear as a mountain stream. Thanks Pete! This is how I thought it would work -

Effectively like the for(;;) contsruct in C.

Regards,

Bob
 
well, after refreshing myself and trying it out, then reading PeteJohnston's very good post. I agree it's ugly and I rally can't see why you would want to perform the structure in this way. But there is always a place for everything.

_________________________________________________________
$str = "sleep is good for you. sleep gives you the energy you need to function";
$Nstr = ereg_replace("sleep","coffee",$str); echo $Nstr;

onpnt2.gif
[/sub]
 
Yep - well was my friends bit of code. Can't get the staff hey!

Bob :)
 
Yep - well it was my friends bit of code. Can't get the staff hey!

Bob :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top