I just saw a post about Python's loop: Trying to understand Python loop using underscore and input
There's a way to loop in python without "variable name":
for _ in range(10):
print("Hello world")
A Java way to do it:
for (int _ = 0; _ < 10; _++) {
System.out.println("Hello world");
}
And eclipse warns me:
'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on.
Maybe I should just stick to i
and write
for (int i = 0; i < 10; i++) {
System.out.println("Hello world");
}
which use a (maybe) not necessary integer variable.
Is there another way to write simple java loop like python loop, maybe more elegantly?