question about terminating my loop

Hello All! I was hoping someone could tell me how to terminate my loop. The purpose of my program is to find the last position of "100" in the array that I am to create, and terminate the loop afterwards. My current output is 4 1. (I would like just 4)When I add "break ;" before System.out.println(i); , my new output becomes 5, and when I add it after this statement, there is no output. Does anyone have a suggestion? I'd appreciate it emensely =) .

publicclass Scores{

publicstaticint[] scores ={95, 100, 72, 88, 100, 86} ;

publicstaticvoid main(String[] args){

for (int i = 5 ; i >= 0 ; i--){

if (scores[i] == 100)

System.out.println(i) ;

}

}

}

[1294 byte] By [maririna] at [2007-11-26 20:20:30]
# 1
Always always always use { and } around the body of an if/else/for/while/etc.: if (scores[i] == 100) {System.out.println(i) ;break; }
jverda at 2007-7-10 0:45:03 > top of Java-index,Other Topics,Algorithms...
# 2
Wow!! Thanks a lot!!! Works perfectly now!maririn
maririna at 2007-7-10 0:45:03 > top of Java-index,Other Topics,Algorithms...
# 3
Do you understand why it wasn't working before?
jverda at 2007-7-10 0:45:03 > top of Java-index,Other Topics,Algorithms...
# 4

If you don't use the brackets for loops/if statements, (but you should use them), you need to indent whats inside the loop/if statement.

Try:

if (scores[i] == 100)

System.out.println(i) ;

Instead of:

if (scores[i] == 100)

System.out.println(i) ;

shlumpha at 2007-7-10 0:45:03 > top of Java-index,Other Topics,Algorithms...