I am pretty new at writing Arduino code. I have seen in some codes I have downloaded a "j" in it and am wondering what it is and what it does. For example it may be "int j; or
void setup(){
for (int jj; jj<sizeof(leds)/sizeof(int);jj++){
pinMode(leds[jj],OUTPUT);
delay(10);
So I was wondering is this a value or a command or what.
And the double letter versions ii and jj and so forth make it a little easier to find instances amongst all the 'i's floating around in the code.
But used as a loop variable like this, any reference to that actual variable will, it is hoped, be found very nearby as it is only valid within the body of the for statement.
True, it's the proper thing to do (and makes the code more readable), however afaik most if not all modern C++ compilers by default initialise a variable to 0 and that code will run as expected starting the count from 0.
I suspect i was short for index, and j was the logical next letter after i, when we needed a second indexing variables.
Besides, in some neolithic languages, i was the start of integer variables, with other letters connoting different variable types. But, that might be misremembering Cobol, some form of Basic, and other early teachings. Not sure. Z8 basic, maybe?
3 -51 -193
now an uninitiaized j
---------
2 30 658
now an uninitiaized j
---------
-7 -22 544
now an uninitiaized j
---------
-5 -60 709
now an uninitiaized j
---------
-3 -58 -508
now an uninitiaized j
---------
-1 27 -497
now an uninitiaized j
---------
-7 -88 -160
now an uninitiaized j
---------
7 9 169
now an uninitiaized j
---------
9 33 560
now an uninitiaized j
---------
5 -84 -722
now an uninitiaized j
---------
now an uninitiaized j after the stack was cleared
j=0
j=1
j=2
... and learned a thing. The uninitialized j lines followed by the line of dashed lines indicate that ``j < 3`' was false.
In old Fortran variables starting with i to n were default integer variable, the other letters were floating point. Not sure how it is now - it has been decades since I've written Fortran.
It's mostly from ForTran. variables did not need to be pre-defined the way they are in C/C++, and variables that began with I through N would be Integers (The first two letters of "INteger", get it?), and everything else was floats. It wasn't uncommon to see nested loops with "i", "ii", "iii"...
There was even an IMPLICIT statement that allowed you to specify the type of otherwise undeclared variables based on the first letter. IMPLICIT COMPLEX Z would mean that any variable name starting with "Z" would be of type COMPLEX
(I'm not sure if this had roots in any previous language. Fortran was pretty early!)
("i" for "Index" is sort of sensible, and "n" for a "natural number" is ok. IMO using "j" or "jj" is to be avoided; a sign that you're an "old fart" thathused to write Fortran code.)
In my FORTRAN punch card days, the convention was that variable names starting with I-N were implicit _IN_tegers, while the rest of A-H,O-Z names were implicit reals. Which more careful programmers could avoid with IMPLICIT NONE.
I seem to remember from Fortran 4 i j k l m and n were by default integer variables
you did not even have to define a variable type just use the identifier which could lead to all sorts of problems - type a variable identifer wrong and there was no compiler warning/error message
3 -51 -193
now an uninitiaized j
---------
2 aized j
j=0
j=1
j=2
9 33 560
now an uninitiaized j
---------
5 -84 -722
now an uninitiaized j
---------
now an uninitiaized j
j=0
j=1
j=2
3 -51 -193
now an uninitiaized j
---------
2 30 658
now an uninitiaized j
---------
-7 -22 544
now an uninitiaized j
---------
-5 -60 709
now an uninitiaized j
---------
-3 -58 -508
now an uninitiaized j
---------
-1 27 -497
now an uninitiaized j
---------
-7 -88 -160
now an uninitiaized j
---------
7 9 169
now an uninitiaized j
---------
9 33 560
now an uninitiaized j
---------
5 -84 -722
now an uninitiaized j
---------
now an uninitiaized j
Absolutely true.
Interesting test results! I've seen my share of weird effects (usually due to having an array reading out of bounds) but didn't see this one yet.
Like x, y, z are coordinates, i, j, k are counters in nested for loops. Just a convention.
Like driving on the right side of the road (where in some countries the wrong side is right side) ( of course).