#A friend sent this to me but I work in python
15 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @vagrant tide! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
goals is an array
and it iterates over the elements
that condition checks to see if the element at index 1 less than p is equal to 0. if so it prints "previous game had no goals" to the console
this code should throw an IndexOutOfBoundsException though
when p = 0, p - 1 = -1 and -1 is an invalid index
because you need the index of to access an element in an array
for loops are meant to simplify the process (In java terms)
you could write ```
int i = 0;
while (i < arr.length) {
//blabla
i++
}
// or
for (int i = 0; i < arr.length; i++) {
//blabla
}
I personally like the latter.
because it should be System.out.println
it probably is in other langs
in Java for loops almost have a single purpose
I mean that's a bit of an overstatement. but when you see a for loop you know what's happening. they are used far more often than while loops in terms of general iteration