Stop at the
first match.

Trace a TypeScript loop one cell at a time. Pud proves it returns the first matching index, or −1n if the target is missing.

linear-search.ts
  1. let index = 0n;
  2. for (const value of values) {
  3. if (value === target) return index;
  4. index += 1n;
  5. }
  6. return -1n;
Read the search proof ↗

values[]

[0]4
[1]8
[2]7
[3]7
[4]3
Ready to step