1*148ee845SSimon J. Gerraty# $NetBSD: directive-for-break.mk,v 1.5 2023/06/01 20:56:35 rillig Exp $ 24fde40d9SSimon J. Gerraty# 34fde40d9SSimon J. Gerraty# Tests for .break in .for loops, which immediately terminates processing of 44fde40d9SSimon J. Gerraty# the surrounding .for loop. 54fde40d9SSimon J. Gerraty 64fde40d9SSimon J. Gerraty 74fde40d9SSimon J. Gerraty# .break terminates the loop early. 84fde40d9SSimon J. Gerraty# This is usually done within a conditional. 94fde40d9SSimon J. Gerraty.for i in 1 2 3 4 5 6 7 8 104fde40d9SSimon J. Gerraty. if $i == 3 114fde40d9SSimon J. GerratyI= $i 124fde40d9SSimon J. Gerraty. break 134fde40d9SSimon J. GerratyI= unreached 144fde40d9SSimon J. Gerraty. endif 154fde40d9SSimon J. Gerraty.endfor 164fde40d9SSimon J. Gerraty.if $I != "3" 174fde40d9SSimon J. Gerraty. error 184fde40d9SSimon J. Gerraty.endif 194fde40d9SSimon J. Gerraty 204fde40d9SSimon J. Gerraty 214fde40d9SSimon J. Gerraty# The .break only breaks out of the immediately surrounding .for loop, any 224fde40d9SSimon J. Gerraty# other .for loops are continued normally. 234fde40d9SSimon J. Gerraty.for outer in o1 o2 o3 244fde40d9SSimon J. Gerraty. for inner in i1 i2 i3 254fde40d9SSimon J. Gerraty. if ${outer} == o2 && ${inner} == i2 264fde40d9SSimon J. Gerraty. break 274fde40d9SSimon J. Gerraty. endif 284fde40d9SSimon J. GerratyCOMBINED+= ${outer}-${inner} 294fde40d9SSimon J. Gerraty. endfor 304fde40d9SSimon J. Gerraty.endfor 314fde40d9SSimon J. Gerraty# Only o2-i2 and o2-i3 are missing. 324fde40d9SSimon J. Gerraty.if ${COMBINED} != "o1-i1 o1-i2 o1-i3 o2-i1 o3-i1 o3-i2 o3-i3" 334fde40d9SSimon J. Gerraty. error 344fde40d9SSimon J. Gerraty.endif 354fde40d9SSimon J. Gerraty 364fde40d9SSimon J. Gerraty 374fde40d9SSimon J. Gerraty# A .break outside the context of a .for loop is an error. 384fde40d9SSimon J. Gerraty.if $I == 0 394fde40d9SSimon J. Gerraty# No parse error, even though the .break occurs outside a .for loop, since 404fde40d9SSimon J. Gerraty# lines from inactive branches are only parsed as far as necessary to see 414fde40d9SSimon J. Gerraty# whether they belong to an .if/.elif/.else/.endif chain. 424fde40d9SSimon J. Gerraty. break 434fde40d9SSimon J. Gerraty.else 444fde40d9SSimon J. Gerraty# expect+1: break outside of for loop 454fde40d9SSimon J. Gerraty. break 464fde40d9SSimon J. Gerraty.endif 474fde40d9SSimon J. Gerraty 484fde40d9SSimon J. Gerraty 494fde40d9SSimon J. Gerraty# Since cond.c 1.335 from 2022-09-02 and before cond.c 1.338 from 2022-09-23, 504fde40d9SSimon J. Gerraty# the following paragraph generated the wrong error message '4294967294 open 514fde40d9SSimon J. Gerraty# conditionals'. 524fde40d9SSimon J. Gerraty.if 1 534fde40d9SSimon J. Gerraty. if 2 544fde40d9SSimon J. Gerraty. for var in value 554fde40d9SSimon J. Gerraty. if 3 564fde40d9SSimon J. Gerraty. break 574fde40d9SSimon J. Gerraty. endif 584fde40d9SSimon J. Gerraty. endfor 594fde40d9SSimon J. Gerraty. endif 604fde40d9SSimon J. Gerraty.endif 61*148ee845SSimon J. Gerraty 62*148ee845SSimon J. Gerraty 63*148ee845SSimon J. Gerraty.for i in 1 64*148ee845SSimon J. Gerraty# expect+1: The .break directive does not take arguments 65*148ee845SSimon J. Gerraty. break 1 66*148ee845SSimon J. Gerraty.endfor 67