I saw this in an example, but I don't understand the meaning behind the loop numbers.
What is the loop beginning at 48 and going to 57 supposed to mean?
If I change the numbers from 0 to 10, it doesn't work, but all the numbers are less than 10 that it prints out in order. However, none of the numbers are between 48 and 57. What is the significance of those numbers of why it is looping? I printed out the numeric value at each char as well, but it is not showing they are different than 1,9,7.
Nathan Milota wrote:I don't know what exactly it does though.
(char) 48 does the inverse of (int) '0'. char is actually a numeric data type, but when you print them they look like text characters. The text character '0' is actually represented by the numeric value 48.
For a full list of what numeric values correspond to what textual characters, see the UTF-16 Basic Multilingual Plane. The most relevant characters for you are in the Basic Latin Block. As you can see, the character '0' is associated with the hexadecimal value 0x30, which corresponds to 48 in decimal.
Carey Brown wrote:you have to do a bunch of mental arithmetic and hope you don't introduce a bug.
I'm lazy. I write tests to watch my six against bugs so I don't have to do mental arithmetic and rely on hope. Your alternative is good in this case though. However, you can't always use "<" if you're trying to reference specific parameters in a different order as they're listed.