pocm@[EMAIL PROTECTED]
wrote:
>
> Hi all,
>
> I'm not a Pascal programmer but I'm trying something with it. I'm
> defining 2 functions and I'm trying to call them with mutual recursion
> as follows:
> program mrecur (i, o);
>
> function doodd(i : integer) : integer;
> begin
> doodd := i + doeven(i - 1);
> end; { doodd }
>
> function doeven(i : integer) : integer;
> begin
> if (i = 0) then 0
> else
> doeven := i + doodd(i / 2);
> end; { doeven }
>
> var init, final : integer;
> begin
> read(init);
> if even(init) then final := doeven(init)
> else
> final := doodd(init);
> end.
>
> However, I cannot have doeven before doodd or the other way around
> since each one calls the other. How can I solve this? In C I would
> write the function prototypes before their declaration but can't seem
> to solve this in Pascal. Can someone give me a hint?
> Cheers,
>
> Paulo Matos
Try a forward declaration.
function doeven(i : integer) : integer; forward;
> function doodd(i : integer) : integer;
> begin
> ...
> end; { doodd }
>
> function doeven(i : integer) : integer;
> begin
...
> end; { doeven }
>
Cheers Hanford