4
$\begingroup$

I have a very simple question. What is the right standard convention to use for declaring arrays?

I understand that for a simple declaration of a variable as an integer, this is the convention:

DECLARE myVar : INTEGER

What about for an integer array of 10 elements?

DECLARE myVar : ARRAY[1,10] of INT

or

DECLARE myVar[1,10] : ARRAY of INT

or something else?

$\endgroup$
7
$\begingroup$

Pseudocode is not a formal language. Declare your arrays however you want, as long as it's obvious what you mean. Including the full limits (as you have in both your array examples) is good, since it means the reader isn't worrying about whether you start your indices at 0 or 1.

$\endgroup$
  • $\begingroup$ That said, some professors have specific requirements for pseudocode, in which case you should defer to your professor's requirements and ask them. $\endgroup$ – jmite Oct 6 '16 at 2:51
3
$\begingroup$

There are no conventions in pseudocode. You can use whatever convention you want, as long as you think that the reader can understand what you mean. If you're not sure that your convention is transparent enough, explain it.

There is no reason to use a programming-language-like convention like you give. How about:

$myVar$ is an integer.
$myArray$ is an array of 10 integers.

In the second case, you can explain that your arrays are always 1-based.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.