for loop compilation errors

public class contains {
public static void main(String[] args) {
    int[] array = new int[] {0, 1, 2, 3, 4};
    int sum = 0;
    for (i=0, i<=array.length, i++) {
        if (array[i] == 4) {
            return sum;
        }
        sum++;
    }
    return 0;
}

}

I’m not sure why this code above fails. When I try to compile it, I get errors like below. Why is this happening? I want to see at what index 4 is at in my array.

contains.java:5: error: not a statement
    for (i=0, i<=array.length, i++) {
               ^
contains.java:5: error: ';' expected
    for (i=0, i<=array.length, i++) {
                                  ^
contains.java:5: error: ';' expected
    for (i=0, i<=array.length, i++) {
                                   ^
contains.java:6: error: illegal start of expression
        if (array[i] == 4) {
        ^
contains.java:6: error: ')' expected
        if (array[i] == 4) {
          ^
contains.java:6: error: not a statement
        if (array[i] == 4) {
                     ^
contains.java:6: error: ';' expected
        if (array[i] == 4) {
                         ^
contains.java:11: error: illegal start of type
        return 0;


Source: syntax

Leave a Reply