|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Position 0 in an array?
Am I missing something or does CF not allow a position 0 in an array?
Here's a snippet of my code: Code:
<cfset choices = ArrayNew(1)> <cfset choices[0] = "Select"> <cfset choices[1] = "Strongly Agree"> <cfset choices[2] = "Agree"> <cfset choices[3] = "Disagree"> <cfset choices[4] = "Strongly Disagree"> <cfset choices[5] = "No Opinion/Not Applicable"> And here's the error I'm getting: The element at position 0 of array variable "CHOICES" cannot be found. If I remove: <cfset choices[0] = "Select"> it executes perfectly. Any help appreciated, wdn2k |
|
#2
|
|||
|
|||
|
the first element in an array always starts with the numeral one. Most other languages start with zero. I personally think it’s much more intuitive to start with one instead of zero, but others would disagree.
|
|
#3
|
||||
|
||||
|
Quote:
That's just weird. To me, more intuitive would be to allow any integer and let the programmer decide what would be more useful for their application. |
|
#4
|
|||
|
|||
|
CF deviates from other languages in this regard. Arrays always start with 1. Yes, it's wierd. But really, it's not very hard to cope with once you know it.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#5
|
|||
|
|||
|
hmmm interesting.. it would be interesting if they could do that because internally (addressing), they are stored pretty much the same way.. then again, it won't be consistent and other people looking at anotehr person's code may be confused...
as the saying goes, just because we can do it, does not mean we have to do it. come to think of it, why was the reason why arrays start at 0 in the first place. My guess it's because its the origin.. so it starts off at 0,0 say... Quote:
|
|
#6
|
|||
|
|||
|
Simply because it makes far more sense for the first element in an array to be element number 1. That's the only reason.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Position 0 in an array? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|