That's part of why I love Java. You can construct a loop like for(char current = 'a'; current <= 'z'; current++).
You can do the same in C/C++ and many other languages.
As a matter of fact, 'j' does not equal 'i1'.
His statement was correct.
'j' == 'i' + 1. These are single quotes representing characters (an integral type), not double quotes representing strings. The + operator literally adds their integral values instead of doing string concatenation (which wouldn't even work in reasonable[1] languages because 1 isn't a string).
[1] it does work in JavaScript, because fuck types I guess.
This is victim blaming! You shouldn't be teaching your languages to be strictly typed, you should be teaching your typeerrors to stop expecting certain types! Let's focus on the real villains here
Anybody remember Fortran? Traditionally, in Fortran the variables I, J, K, L, M, N were always integers while others like A, B, C and X, Y, Z were floats - smart programmers don't use floats for loop counters.
In any C based language you could write for(ShapeWithCorners current = new Point(); current.Corners <= 20; current++) and each iteration would be a shape with one corner more if you really want to do that. It is just a question of properly overriding the ++ operator.
Not all C based languages allow you to overload operators. You’re thinking of C++ overloading, but that doesn’t work in Java or Objective-C, or even C itself. It would work in Objective-C++ but that’s only because it’s an unholy mix of Objective-C and C++.
View all comments
Show parent comment
98
u/DudeitsCarl Jun 06 '20
I think it’s j == i+1