I was performing some tests in a program I'm making right now and I came across the following situation. Summarizing I'll put the following:
class ForTest {
public static void main(String args[]) throws java.io.IOException{
int i;
System.out.println("Press S to stop.");
for(i = 0; (char) System.in.read() != 'S'; i++)
System.out.println("Pass #" + i);
}
}
the output is:
Press S to stop.
g
Pass #0
Pass #1
2
Pass #2
Pass #3
4
Pass #4
Pass #5
5
Pass #6
Pass #7
S
In theory it should iterate one by one each time I type a wrong char but it perform the sysout twice. I'm curious why does this for statement behave like this.
Regards!