The code below is a (simplified version of) nested loop , used to init a 2d array of Pixel objects:
(it is inside a method with two parameters - int height and int width. screen is already declared before)
However, this code (called with width and height both equal to 10) only inits 9 Objects in first row. If i change the > and < to >= and <=, it results in index out of bounds exception. What is happening here??
Never be afraid to write code to test your beliefs. It should be trivial to pull this into a new, stand alone program, and try it out. You can include some additional println statements. I's suggest something like on line 10:
you could also create a new counter outside the loop and increment it each time you create a new pixel, and print it's value as well - either as you go, or when your done with both loops have a "i created X objects in total".
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors