Self-closing for loop generates warning by IDEA's Analyze > Inspect code ...
Self-closing for loops are very useful if you simply want to pick out a match to some object (or some condition for that object) within a collection class.
For example, if I want to find a match to a value 23 in an int array, I can write:
. . . . . .
int[] myArray = new int[2000000];
myArray[99] = 23;
int myValue = 23;
for(int i = 0; i < myArray.length && myArray[i] != myValue; i++);
if (i < myArray.length)
System.out.println("Value found at index: " + i);
else
System.out.println("Value not in myArray");
. . . . . . .
But the IntelliJ IDEA code inspector always issues a warning on each of this type of for loop.
Probable Bug: 'for' statement has empty body.
Is there some inherent insecurity with this construct ?
Personally, I find it (nearly essentially!) handy and efficient for finding an entry in an array or collection.
Please sign in to leave a comment.
Hello,
Please follow the issue created for your report at YouTrack:
https://youtrack.jetbrains.com/issue/IDEA-217938
Thank you!
Why not answer it here ?