Create a function to print an array

111 Views Asked by At

I am having trouble creating a function to print arrays that works with any type. I have attempted the following function and main program:

Here's the function

Here's the main program

However, it does not work and I keep encountering new problems even after attempting to correct them. The error message is below:

Here's the error message

Any suggestions on what I am doing wrong?

1

There are 1 best solutions below

0
Costantino Grana On

There's no reason why you should check a value of -1 as an indicator of array end. There is a specific function: Size(). So your function could be:

printE

The XML version:

    <function name="printE" type="None" variable="">
        <parameters>
            <parameter name="tab" type="Integer" array="True"/>
        </parameters>
        <body>
            <declare name="i" type="Integer" array="False" size=""/>
            <for variable="i" start="0" end="Size(tab) - 1" direction="inc" step="1">
                <output expression="tab[i]" newline="True"/>
            </for>
        </body>
    </function>