IO delay causes 2 iterations in for loop in JAVA : <p>I was testing some piece of code and came across something interesting on which I would need some expert opinion.</p>

<p>A simple program that stops the loop when the input is <code>s</code> but seems the on each input the loop is iterated twice, i guess that's because of the IO delay. Correct me if I am wrong.</p>

<pre><code>public static void main(String[] args) throws java.io.IOException {
        int i;
        System.out.println("Type s to stop.");
        for(i = 0; ; i++) {
            char value = (char) System.in.read();
            if(value=='s'){
                break;
            }
            System.out.println("Pass # " + i);
        }
    }
</code></pre>

<p><strong>output:</strong></p>

<p><a href="https://i.stack.imgur.com/rE5IZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rE5IZ.png" alt="enter image description here"></a></p>
