E.g. I have this array:
type
OptionRange = array[ 1..9 ] of integer;
How do I check if array[x] exists?
Actually, I want to limit user input with the array index. Am I doing the wrong thing? Is there a better practical solution?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Free Pascal and the Borland dialects (and perhaps elsewhere as well), you can use the
LowandHighfunctions on the array type or a variable of the array type. I see this used most often to determine the bounds forforloops:You can also define a subrange type and then use it to define both the array and the index variables you use on the array:
Then, when you have range checking enabled (assuming your compiler offers such a feature) and you use a value that’s outside the range for
OptionRangeindices, you’ll get a run-time error that you can catch and handle however you want.I’m not really sure what an option range is or why an array of nine integers would be used to represent one, but I figure that’s a name-selection issue.