Hey, I don't understand this concept
This is the algorithm from the excel book to find the length
Code:
BEGIN SUBPROGRAM StringLength(String)
Index = 1
WHILE String[Index] contains a character
Increment Index
ENDWHILE
Length = Index - 1
RETURN Length
END SUBPROGRAM StringLength
say if there are 20 items, start at 1 going to 20 = 20 items, therefore why are they subtracting 1? that would cause a one off error?
and IF I wanted to start at index = 0 what would the length code be? Length = Index + 1 ?
Also do we need to write SUBPROGRAM? I usually just write the intrinsic name of the algorithm.
and one other thing if we are swapping elements in an array how do we reference it?
Is Swap(Array[Index], Array[Index + 1]) fine?
I've seen it as Swap(Array, Index, Index + 1) is that also correct?