I have a question about the following code. 

```
public class test
{
    public static void main (String[] args)
    {
    int a = 0;
    int b = 0;

    for (int i = 0; i < 5; i++); {
        b = b + a;
        a++;
    }
    System.out.println(b);

```

Why is the output of this 0? As you can see I'm a complete beginner but why does it not go through the loop 4 times before printing the answer?

Help is appreciated!

//Confused beginner
['https://Stackoverflow.com/questions/40208857', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7062013/']
For loops iterate over the statement or block immediately following the for statement. In this case you have a stray semicolon causing the next statement to be empty. Remove it and your code will work as indended

Replace:

```
for (int i = 0; i < 5; i++); { 
    b = b + a;
    a++;
}

```

-with-

```
for (int i = 0; i < 5; i++) {
    b = b + a;
    a++;
}

```
Just remove the semicolon after the for loop statement, otherwise the body surrounded by the curly braces will not be considered under the for loop.

Replace the following:

```
for (int i = 0; i < 5; i++); {
                           ^ <--- remove it  
    b = b + a;
    a++;
}

```

by

```
for (int i = 0; i < 5; i++); {
    b = b + a;
    a++;
}

```