Repository: dotnet/aspnetcore
File: src/Http/Routing/src/ValidationEndpointFilterFactory.cs (C#)

Code before:
                continue;
            }

            if (options.TryGetValidatableParameterInfo(parameters[i], out var validatableParameter))
            {
                validatableParameters.Add(new ValidatableParameterEntry(
                    i,
                    validatableParameter,
                    GetDisplayName(parameters[i])));
            }
        }

        if (validatableParameters.Count == 0)
        {
            return next;
        }

        return async (context) =>
        {
            ValidateContext? validateContext = null;

            foreach (var entry in validatableParameters)
            {
                if (entry.Index >= context.Arguments.Count)
                {
                    continue;
                }

                var argument = context.Arguments[entry.Index];
                if (argument is null)
                {
                    continue;
                }

                var validationContext = new ValidationContext(argument, entry.DisplayName, context.HttpContext.RequestServices, items: null);

                if (validateContext == null)
                {
                    validateContext = new ValidateContext
                    {
                        ValidationOptions = options,
                        ValidationContext = validationContext
                    };
                }
                else
                {
                    validateContext.ValidationContext = validationContext;
                }

                await entry.Parameter.ValidateAsync(argument, validateContext, context.HttpContext.RequestAborted);
            }

Review comment (suggestion):
```suggestion
                    break;
```
? 
In the next iteration then `entry.Index` will be even higher, so that condition will be true again, so exit early instead.

Code after:

        if (validatableParameters is null || validatableParameters.Count == 0)
        {
            return next;
        }

        return async (context) =>
        {
            ValidateContext? validateContext = null;

            foreach (var entry in validatableParameters)
            {
                if (entry.Index >= context.Arguments.Count)
                {
                    break;
                }

                var argument = context.Arguments[entry.Index];
                if (argument is null)
                {
                    continue;
                }

                var validationContext = new ValidationContext(argument, entry.DisplayName, context.HttpContext.RequestServices, items: null);

                if (validateContext == null)
                {
                    validateContext = new ValidateContext
                    {
                        ValidationOptions = options,
                        ValidationContext = validationContext
                    };
                }
                else
                {
                    validateContext.ValidationContext = validationContext;
                }

                await entry.Parameter.ValidateAsync(argument, validateContext, context.HttpContext.RequestAborted);
            }

            if (validateContext is { ValidationErrors.Count: > 0 })
            {
                context.HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
                context.HttpContext.Response.ContentType = "application/problem+json";
                return await ValueTask.FromResult(new HttpValidationProblemDetails(validateContext.ValidationErrors));
            }

            return await next(context);
        };
    }