Vocabulary/breakdot

From J Wiki
Jump to navigation Jump to search

>> <<   Back to: Vocabulary Thru to: Dictionary

break. Terminate loop Control

Valid only inside an explicit definition.


Stops executing any further sentences in the current block during the current iteration, plus any further iterations.

Use within the block delimited by…


More Information

The difference between (break.) and (continue.)

  • (break.) prematurely terminates the whole loop
  • (continue.) prematurely terminates just the current iteration.
   
test_break=: 3 : 0
for_i. i.6 do.
  smoutput 'before ',":i
  if. i>:3 do. break. end.
  smoutput 'after ',":i
end.
)

test_continue=: 3 : 0
for_i. i.6 do.
  smoutput 'BEFORE ',":i
  if. i>:3 do. continue. end.
  smoutput 'AFTER ',":i
end.
)
   
   test_break''
before 0
after 0
before 1
after 1
before 2
after 2
before 3
   test_continue''
BEFORE 0
AFTER 0
BEFORE 1
AFTER 1
BEFORE 2
AFTER 2
BEFORE 3
BEFORE 4
BEFORE 5

Related Primitives

Terminate iteration (continue.)