Search code examples
arrayspseudocode

Setting array in pseudocode


If I have an array A of n elements and want to set the elements 1 to m to zero, how should I write this in pseudocode? We all know, depending how "primitive" your real programming language is, you may have to write a for-loop for that.

Would it be ok to write

A[1, ..., m] <- 0

Seems a bit confusing... any compact alternatives (no for-loop)?

Thanks in advance!


Solution

  • We all agree that your pseudocode looks ok, but I also agree it doesn't describe everything you told with words, as n can be greater than m for example, right? What I thought about when I read your question was doing something like this:

    A <- zeros(A,m) // zeros(arry,n) returns the same array 'arry' but with 0s in the entries from 1 to n
    

    As it's pseudocode, just making a comment next to the assignment with a brief description of the invented function should be ok to me I guess.

    Hope it helped!