1*4fde40d9SSimon J. Gerraty# $NetBSD: directive-for-break.mk,v 1.3 2022/09/24 10:52:05 rillig Exp $ 2*4fde40d9SSimon J. Gerraty# 3*4fde40d9SSimon J. Gerraty# Tests for .break in .for loops, which immediately terminates processing of 4*4fde40d9SSimon J. Gerraty# the surrounding .for loop. 5*4fde40d9SSimon J. Gerraty 6*4fde40d9SSimon J. Gerraty 7*4fde40d9SSimon J. Gerraty# .break terminates the loop early. 8*4fde40d9SSimon J. Gerraty# This is usually done within a conditional. 9*4fde40d9SSimon J. Gerraty.for i in 1 2 3 4 5 6 7 8 10*4fde40d9SSimon J. Gerraty. if $i == 3 11*4fde40d9SSimon J. GerratyI= $i 12*4fde40d9SSimon J. Gerraty. break 13*4fde40d9SSimon J. GerratyI= unreached 14*4fde40d9SSimon J. Gerraty. endif 15*4fde40d9SSimon J. Gerraty.endfor 16*4fde40d9SSimon J. Gerraty.if $I != "3" 17*4fde40d9SSimon J. Gerraty. error 18*4fde40d9SSimon J. Gerraty.endif 19*4fde40d9SSimon J. Gerraty 20*4fde40d9SSimon J. Gerraty 21*4fde40d9SSimon J. Gerraty# The .break only breaks out of the immediately surrounding .for loop, any 22*4fde40d9SSimon J. Gerraty# other .for loops are continued normally. 23*4fde40d9SSimon J. Gerraty.for outer in o1 o2 o3 24*4fde40d9SSimon J. Gerraty. for inner in i1 i2 i3 25*4fde40d9SSimon J. Gerraty. if ${outer} == o2 && ${inner} == i2 26*4fde40d9SSimon J. Gerraty. break 27*4fde40d9SSimon J. Gerraty. endif 28*4fde40d9SSimon J. GerratyCOMBINED+= ${outer}-${inner} 29*4fde40d9SSimon J. Gerraty. endfor 30*4fde40d9SSimon J. Gerraty.endfor 31*4fde40d9SSimon J. Gerraty# Only o2-i2 and o2-i3 are missing. 32*4fde40d9SSimon J. Gerraty.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3" 33*4fde40d9SSimon J. Gerraty. error 34*4fde40d9SSimon J. Gerraty.endif 35*4fde40d9SSimon J. Gerraty 36*4fde40d9SSimon J. Gerraty 37*4fde40d9SSimon J. Gerraty# A .break outside the context of a .for loop is an error. 38*4fde40d9SSimon J. Gerraty.if $I == 0 39*4fde40d9SSimon J. Gerraty# No parse error, even though the .break occurs outside a .for loop, since 40*4fde40d9SSimon J. Gerraty# lines from inactive branches are only parsed as far as necessary to see 41*4fde40d9SSimon J. Gerraty# whether they belong to an .if/.elif/.else/.endif chain. 42*4fde40d9SSimon J. Gerraty. break 43*4fde40d9SSimon J. Gerraty.else 44*4fde40d9SSimon J. Gerraty# expect+1: break outside of for loop 45*4fde40d9SSimon J. Gerraty. break 46*4fde40d9SSimon J. Gerraty.endif 47*4fde40d9SSimon J. Gerraty 48*4fde40d9SSimon J. Gerraty 49*4fde40d9SSimon J. Gerraty# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23, 50*4fde40d9SSimon J. Gerraty# the following paragraph generated the wrong error message '4294967294 open 51*4fde40d9SSimon J. Gerraty# conditionals'. 52*4fde40d9SSimon J. Gerraty.if 1 53*4fde40d9SSimon J. Gerraty. if 2 54*4fde40d9SSimon J. Gerraty. for var in value 55*4fde40d9SSimon J. Gerraty. if 3 56*4fde40d9SSimon J. Gerraty. break 57*4fde40d9SSimon J. Gerraty. endif 58*4fde40d9SSimon J. Gerraty. endfor 59*4fde40d9SSimon J. Gerraty. endif 60*4fde40d9SSimon J. Gerraty.endif 61