ThreeState (@NotNull PsiStatement statement, @NotNull PsiVariable loopVar) { PsiIfStatement ifStatement = tryCast(statement, PsiIfStatement.class); if (ifStatement == null) return ThreeState.UNSURE; PsiExpression condition = ifStatement.getCondition(); if (condition == null) return ThreeState.UNSURE; PsiBinaryExpression binaryExpression = tryCast(condition, PsiBinaryExpression.class); if (binaryExpression == null) return ThreeState.UNSURE; PsiExpression comparedEqWithZero = ExpressionUtils.getValueComparedWithZero(binaryExpression); if (comparedEqWithZero != null) { if (!ExpressionUtils.isReferenceTo(comparedEqWithZero, loopVar)) return ThreeState.UNSURE; return ThreeState.YES; } PsiExpression notEqWithZero = getExpressionComparedToZero(binaryExpression); if (notEqWithZero == null || !ExpressionUtils.isReferenceTo(notEqWithZero, loopVar)) return ThreeState.UNSURE; return ThreeState.NO; }