Win a copy of Java by Comparison (eBook) this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does this for-loop break when iterating through a multidimensional array?  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I'm trying to do is create an editable calendar made up of arrays.

First I create some variables:

Then I try to use nested for-loops to allow the user to say when they are usually asleep:

When I was building, I always had

var quantifiedMonth

set to 0, which allowed the program to work. Then I realized that if I set it to 1, then it breaks. I can't wrap my head around why, because of the output that I got when the program worked.

Say I had

then my output would be

but when

the program crashes. I can't wrap my head around why that is. To my mind, I shouldn't be able to get the output I do when

Please help. I tried to be thorough in my question, but if I'm being vague about something, please let me know.

Here's some screenshots of the errors I get

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!