Skip to content

Files

Latest commit

 

History

History
25 lines (16 loc) · 518 Bytes

UntilInsteadOfRangeTo.md

File metadata and controls

25 lines (16 loc) · 518 Bytes

Pattern: Missing use of until

Issue: -

Description

until is applicable in cases where the upper range value is described as some value subtracted by 1. It helps to prevent off-by-one errors.

Example of incorrect code:

for (i in 0 .. 10 - 1) {}
val range = 0 .. 10 - 1

Example of correct code:

for (i in 0 until 10) {}
val range = 0 until 10

Further Reading