Skip to content

Commit 2cd73c6

Browse files
committed
FEAT: break/return now has priority over regular return value from remove-each
1 parent 0f4d26c commit 2cd73c6

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/core/n-loop.c

+1
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ skip_hidden: ;
489489
if (mode == LM_REMOVE) {
490490
// Remove hole (updates tail):
491491
if (windex < index) Remove_Series(series, windex, index - windex);
492+
if (err == 2) return R_TOS1; // If BREAK/RETURN
492493
if (return_count) {
493494
index -= windex;
494495
SET_INTEGER(DS_RETURN, IS_MAP(value) ? index / 2 : index);

src/tests/units/series-test.r3

+5
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,11 @@ Rebol [
984984
--assert s = [2 3 4]
985985
--assert 1 = remove-each/count n s: [1 2 3 4] [if n = 2 [break] true]
986986
--assert s = [2 3 4]
987+
--test-- "break/return in remove-each"
988+
--assert 'x = remove-each n s: [1 2 3 4] [if n = 2 [break/return 'x] true]
989+
--assert s = [2 3 4]
990+
--assert 'x = remove-each/count n s: [1 2 3 4] [if n = 2 [break/return 'x] true]
991+
--assert s = [2 3 4]
987992

988993
===end-group===
989994

0 commit comments

Comments
 (0)