According to the Java Language Specification:
BasicForStatement:
for ( ForInitopt ; Expressionopt ; ForUpdateopt ) Statement
ForStatementNoShortIf:
for ( ForInitopt ; Expressionopt ; ForUpdateopt ) StatementNoShortIf
ForInit:
StatementExpressionList
LocalVariableDeclaration
ForUpdate:
StatementExpressionList
StatementExpressionList:
StatementExpression
StatementExpressionList , StatementExpression
14.14.1.2. Iteration of for Statement
Next, a for iteration step is performed, as follows:
If the Expression is present, it is evaluated. If the result is of
type Boolean, it is subject to unboxing conversion (§5.1.8).
In other words, t < Integer.parseInt(in.readLine()) is executed once per each iteration of the loop.
It is explained better in the Java Tutorial:
The for statement provides a compact way to iterate over a range of
values. Programmers often refer to it as the "for loop" because of the
way in which it repeatedly loops until a particular condition is
satisfied. The general form of the for statement can be expressed as
follows:
for (initialization; termination; increment) {
statement(s) }
When using this version of the for statement, keep in mind that:
- The initialization expression initializes the loop; it's executed once, as the loop begins.
- When the termination expression evaluates to false, the loop terminates.
- The increment expression is invoked after each iteration through the loop; it is perfectly acceptable for this expression to increment or
decrement a value.
If you want something similar to for t in range(int(input()), you can use the Streams API:
import static java.lang.Integer.parseInt;
import static java.lang.System.console;
// option 1
try (final BufferedReader console = new
BufferedReader(new InputStreamReader(System.in))) {
IntStream.range(0, parseInt(console.readLine())).forEach(i -> {
System.out.println(i);
});
}
// option 2 (fails in some IDEs as console() will return null)
IntStream.range(0, parseInt(console().readLine())).forEach(i -> {
System.out.println(i);
});
forloop, the condition is executed on each iteration. That is just howforloops work in java.IntStream.range(1, in.readLine()).forEach(i -> { /* do something */});