Break/Continue Puzzle: Skip Multiples

Medium ⏱ 12 min 62% acceptance ★★★★★ 4.7
Write a function collect_until_stop(nums, skip_multiple_of, stop_at) that iterates over nums, skipping (via continue) any value that is a multiple of skip_multiple_of, and stopping entirely (via break) the moment it encounters the value stop_at. Return the list of collected values (values that were kept before stopping).

Examples

Example 1
Input
collect_until_stop([1, 2, 3, 4, 5, 6, 8], 3, 5)
Output
[1, 2, 4]
Explanation

3 is skipped as a multiple of 3; the loop stops when it reaches 5, so 6 and 8 are never examined.

Constraints

  • nums is a list of integers.
  • skip_multiple_of is a positive integer.

Topics

Loopsbreak/continue

Companies

ServiceNowSalesforce

Hints

Hint 1

Check the stop_at condition first with `break` before checking the skip condition.

Hint 2

Use `continue` to skip appending multiples without ending the loop.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.