1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# We have the following types of loop: 4*0Sstevel@tonic-gate# 5*0Sstevel@tonic-gate# 1a) while(A) {B} 6*0Sstevel@tonic-gate# 1b) B while A; 7*0Sstevel@tonic-gate# 8*0Sstevel@tonic-gate# 2a) until(A) {B} 9*0Sstevel@tonic-gate# 2b) B until A; 10*0Sstevel@tonic-gate# 11*0Sstevel@tonic-gate# 3a) for(@A) {B} 12*0Sstevel@tonic-gate# 3b) B for A; 13*0Sstevel@tonic-gate# 14*0Sstevel@tonic-gate# 4a) for (A;B;C) {D} 15*0Sstevel@tonic-gate# 16*0Sstevel@tonic-gate# 5a) { A } # a bare block is a loop which runs once 17*0Sstevel@tonic-gate# 18*0Sstevel@tonic-gate# Loops of type (b) don't allow for next/last/redo style 19*0Sstevel@tonic-gate# control, so we ignore them here. Type (a) loops can 20*0Sstevel@tonic-gate# all be labelled, so there are ten possibilities (each 21*0Sstevel@tonic-gate# of 5 types, labelled/unlabelled). We therefore need 22*0Sstevel@tonic-gate# thirty tests to try the three control statements against 23*0Sstevel@tonic-gate# the ten types of loop. For the first four types it's useful 24*0Sstevel@tonic-gate# to distinguish the case where next re-iterates from the case 25*0Sstevel@tonic-gate# where it leaves the loop. That makes 38. 26*0Sstevel@tonic-gate# All these tests rely on "last LABEL" 27*0Sstevel@tonic-gate# so if they've *all* failed, maybe you broke that... 28*0Sstevel@tonic-gate# 29*0Sstevel@tonic-gate# These tests are followed by an extra test of nested loops. 30*0Sstevel@tonic-gate# Feel free to add more here. 31*0Sstevel@tonic-gate# 32*0Sstevel@tonic-gate# -- .robin. <robin@kitsite.com> 2001-03-13 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gateprint "1..43\n"; 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gatemy $ok; 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate## while() loop without a label 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gateTEST1: { # redo 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate $ok = 0; 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate my $x = 1; 45*0Sstevel@tonic-gate my $first_time = 1; 46*0Sstevel@tonic-gate while($x--) { 47*0Sstevel@tonic-gate if (!$first_time) { 48*0Sstevel@tonic-gate $ok = 1; 49*0Sstevel@tonic-gate last TEST1; 50*0Sstevel@tonic-gate } 51*0Sstevel@tonic-gate $ok = 0; 52*0Sstevel@tonic-gate $first_time = 0; 53*0Sstevel@tonic-gate redo; 54*0Sstevel@tonic-gate last TEST1; 55*0Sstevel@tonic-gate } 56*0Sstevel@tonic-gate continue { 57*0Sstevel@tonic-gate $ok = 0; 58*0Sstevel@tonic-gate last TEST1; 59*0Sstevel@tonic-gate } 60*0Sstevel@tonic-gate $ok = 0; 61*0Sstevel@tonic-gate} 62*0Sstevel@tonic-gateprint ($ok ? "ok 1\n" : "not ok 1\n"); 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gateTEST2: { # next (succesful) 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate $ok = 0; 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate my $x = 2; 69*0Sstevel@tonic-gate my $first_time = 1; 70*0Sstevel@tonic-gate my $been_in_continue = 0; 71*0Sstevel@tonic-gate while($x--) { 72*0Sstevel@tonic-gate if (!$first_time) { 73*0Sstevel@tonic-gate $ok = $been_in_continue; 74*0Sstevel@tonic-gate last TEST2; 75*0Sstevel@tonic-gate } 76*0Sstevel@tonic-gate $ok = 0; 77*0Sstevel@tonic-gate $first_time = 0; 78*0Sstevel@tonic-gate next; 79*0Sstevel@tonic-gate last TEST2; 80*0Sstevel@tonic-gate } 81*0Sstevel@tonic-gate continue { 82*0Sstevel@tonic-gate $been_in_continue = 1; 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate $ok = 0; 85*0Sstevel@tonic-gate} 86*0Sstevel@tonic-gateprint ($ok ? "ok 2\n" : "not ok 2\n"); 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gateTEST3: { # next (unsuccesful) 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate $ok = 0; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate my $x = 1; 93*0Sstevel@tonic-gate my $first_time = 1; 94*0Sstevel@tonic-gate my $been_in_loop = 0; 95*0Sstevel@tonic-gate my $been_in_continue = 0; 96*0Sstevel@tonic-gate while($x--) { 97*0Sstevel@tonic-gate $been_in_loop = 1; 98*0Sstevel@tonic-gate if (!$first_time) { 99*0Sstevel@tonic-gate $ok = 0; 100*0Sstevel@tonic-gate last TEST3; 101*0Sstevel@tonic-gate } 102*0Sstevel@tonic-gate $ok = 0; 103*0Sstevel@tonic-gate $first_time = 0; 104*0Sstevel@tonic-gate next; 105*0Sstevel@tonic-gate last TEST3; 106*0Sstevel@tonic-gate } 107*0Sstevel@tonic-gate continue { 108*0Sstevel@tonic-gate $been_in_continue = 1; 109*0Sstevel@tonic-gate } 110*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 111*0Sstevel@tonic-gate} 112*0Sstevel@tonic-gateprint ($ok ? "ok 3\n" : "not ok 3\n"); 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gateTEST4: { # last 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate $ok = 0; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate my $x = 1; 119*0Sstevel@tonic-gate my $first_time = 1; 120*0Sstevel@tonic-gate while($x++) { 121*0Sstevel@tonic-gate if (!$first_time) { 122*0Sstevel@tonic-gate $ok = 0; 123*0Sstevel@tonic-gate last TEST4; 124*0Sstevel@tonic-gate } 125*0Sstevel@tonic-gate $ok = 0; 126*0Sstevel@tonic-gate $first_time = 0; 127*0Sstevel@tonic-gate last; 128*0Sstevel@tonic-gate last TEST4; 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate continue { 131*0Sstevel@tonic-gate $ok = 0; 132*0Sstevel@tonic-gate last TEST4; 133*0Sstevel@tonic-gate } 134*0Sstevel@tonic-gate $ok = 1; 135*0Sstevel@tonic-gate} 136*0Sstevel@tonic-gateprint ($ok ? "ok 4\n" : "not ok 4\n"); 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate## until() loop without a label 140*0Sstevel@tonic-gate 141*0Sstevel@tonic-gateTEST5: { # redo 142*0Sstevel@tonic-gate 143*0Sstevel@tonic-gate $ok = 0; 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate my $x = 0; 146*0Sstevel@tonic-gate my $first_time = 1; 147*0Sstevel@tonic-gate until($x++) { 148*0Sstevel@tonic-gate if (!$first_time) { 149*0Sstevel@tonic-gate $ok = 1; 150*0Sstevel@tonic-gate last TEST5; 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate $ok = 0; 153*0Sstevel@tonic-gate $first_time = 0; 154*0Sstevel@tonic-gate redo; 155*0Sstevel@tonic-gate last TEST5; 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate continue { 158*0Sstevel@tonic-gate $ok = 0; 159*0Sstevel@tonic-gate last TEST5; 160*0Sstevel@tonic-gate } 161*0Sstevel@tonic-gate $ok = 0; 162*0Sstevel@tonic-gate} 163*0Sstevel@tonic-gateprint ($ok ? "ok 5\n" : "not ok 5\n"); 164*0Sstevel@tonic-gate 165*0Sstevel@tonic-gateTEST6: { # next (succesful) 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate $ok = 0; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate my $x = 0; 170*0Sstevel@tonic-gate my $first_time = 1; 171*0Sstevel@tonic-gate my $been_in_continue = 0; 172*0Sstevel@tonic-gate until($x++ >= 2) { 173*0Sstevel@tonic-gate if (!$first_time) { 174*0Sstevel@tonic-gate $ok = $been_in_continue; 175*0Sstevel@tonic-gate last TEST6; 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate $ok = 0; 178*0Sstevel@tonic-gate $first_time = 0; 179*0Sstevel@tonic-gate next; 180*0Sstevel@tonic-gate last TEST6; 181*0Sstevel@tonic-gate } 182*0Sstevel@tonic-gate continue { 183*0Sstevel@tonic-gate $been_in_continue = 1; 184*0Sstevel@tonic-gate } 185*0Sstevel@tonic-gate $ok = 0; 186*0Sstevel@tonic-gate} 187*0Sstevel@tonic-gateprint ($ok ? "ok 6\n" : "not ok 6\n"); 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gateTEST7: { # next (unsuccesful) 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate $ok = 0; 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate my $x = 0; 194*0Sstevel@tonic-gate my $first_time = 1; 195*0Sstevel@tonic-gate my $been_in_loop = 0; 196*0Sstevel@tonic-gate my $been_in_continue = 0; 197*0Sstevel@tonic-gate until($x++) { 198*0Sstevel@tonic-gate $been_in_loop = 1; 199*0Sstevel@tonic-gate if (!$first_time) { 200*0Sstevel@tonic-gate $ok = 0; 201*0Sstevel@tonic-gate last TEST7; 202*0Sstevel@tonic-gate } 203*0Sstevel@tonic-gate $ok = 0; 204*0Sstevel@tonic-gate $first_time = 0; 205*0Sstevel@tonic-gate next; 206*0Sstevel@tonic-gate last TEST7; 207*0Sstevel@tonic-gate } 208*0Sstevel@tonic-gate continue { 209*0Sstevel@tonic-gate $been_in_continue = 1; 210*0Sstevel@tonic-gate } 211*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 212*0Sstevel@tonic-gate} 213*0Sstevel@tonic-gateprint ($ok ? "ok 7\n" : "not ok 7\n"); 214*0Sstevel@tonic-gate 215*0Sstevel@tonic-gateTEST8: { # last 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate $ok = 0; 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate my $x = 0; 220*0Sstevel@tonic-gate my $first_time = 1; 221*0Sstevel@tonic-gate until($x++ == 10) { 222*0Sstevel@tonic-gate if (!$first_time) { 223*0Sstevel@tonic-gate $ok = 0; 224*0Sstevel@tonic-gate last TEST8; 225*0Sstevel@tonic-gate } 226*0Sstevel@tonic-gate $ok = 0; 227*0Sstevel@tonic-gate $first_time = 0; 228*0Sstevel@tonic-gate last; 229*0Sstevel@tonic-gate last TEST8; 230*0Sstevel@tonic-gate } 231*0Sstevel@tonic-gate continue { 232*0Sstevel@tonic-gate $ok = 0; 233*0Sstevel@tonic-gate last TEST8; 234*0Sstevel@tonic-gate } 235*0Sstevel@tonic-gate $ok = 1; 236*0Sstevel@tonic-gate} 237*0Sstevel@tonic-gateprint ($ok ? "ok 8\n" : "not ok 8\n"); 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate## for(@array) loop without a label 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gateTEST9: { # redo 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate $ok = 0; 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate my $first_time = 1; 246*0Sstevel@tonic-gate for(1) { 247*0Sstevel@tonic-gate if (!$first_time) { 248*0Sstevel@tonic-gate $ok = 1; 249*0Sstevel@tonic-gate last TEST9; 250*0Sstevel@tonic-gate } 251*0Sstevel@tonic-gate $ok = 0; 252*0Sstevel@tonic-gate $first_time = 0; 253*0Sstevel@tonic-gate redo; 254*0Sstevel@tonic-gate last TEST9; 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate continue { 257*0Sstevel@tonic-gate $ok = 0; 258*0Sstevel@tonic-gate last TEST9; 259*0Sstevel@tonic-gate } 260*0Sstevel@tonic-gate $ok = 0; 261*0Sstevel@tonic-gate} 262*0Sstevel@tonic-gateprint ($ok ? "ok 9\n" : "not ok 9\n"); 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gateTEST10: { # next (succesful) 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate $ok = 0; 267*0Sstevel@tonic-gate 268*0Sstevel@tonic-gate my $first_time = 1; 269*0Sstevel@tonic-gate my $been_in_continue = 0; 270*0Sstevel@tonic-gate for(1,2) { 271*0Sstevel@tonic-gate if (!$first_time) { 272*0Sstevel@tonic-gate $ok = $been_in_continue; 273*0Sstevel@tonic-gate last TEST10; 274*0Sstevel@tonic-gate } 275*0Sstevel@tonic-gate $ok = 0; 276*0Sstevel@tonic-gate $first_time = 0; 277*0Sstevel@tonic-gate next; 278*0Sstevel@tonic-gate last TEST10; 279*0Sstevel@tonic-gate } 280*0Sstevel@tonic-gate continue { 281*0Sstevel@tonic-gate $been_in_continue = 1; 282*0Sstevel@tonic-gate } 283*0Sstevel@tonic-gate $ok = 0; 284*0Sstevel@tonic-gate} 285*0Sstevel@tonic-gateprint ($ok ? "ok 10\n" : "not ok 10\n"); 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gateTEST11: { # next (unsuccesful) 288*0Sstevel@tonic-gate 289*0Sstevel@tonic-gate $ok = 0; 290*0Sstevel@tonic-gate 291*0Sstevel@tonic-gate my $first_time = 1; 292*0Sstevel@tonic-gate my $been_in_loop = 0; 293*0Sstevel@tonic-gate my $been_in_continue = 0; 294*0Sstevel@tonic-gate for(1) { 295*0Sstevel@tonic-gate $been_in_loop = 1; 296*0Sstevel@tonic-gate if (!$first_time) { 297*0Sstevel@tonic-gate $ok = 0; 298*0Sstevel@tonic-gate last TEST11; 299*0Sstevel@tonic-gate } 300*0Sstevel@tonic-gate $ok = 0; 301*0Sstevel@tonic-gate $first_time = 0; 302*0Sstevel@tonic-gate next; 303*0Sstevel@tonic-gate last TEST11; 304*0Sstevel@tonic-gate } 305*0Sstevel@tonic-gate continue { 306*0Sstevel@tonic-gate $been_in_continue = 1; 307*0Sstevel@tonic-gate } 308*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 309*0Sstevel@tonic-gate} 310*0Sstevel@tonic-gateprint ($ok ? "ok 11\n" : "not ok 11\n"); 311*0Sstevel@tonic-gate 312*0Sstevel@tonic-gateTEST12: { # last 313*0Sstevel@tonic-gate 314*0Sstevel@tonic-gate $ok = 0; 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate my $first_time = 1; 317*0Sstevel@tonic-gate for(1..10) { 318*0Sstevel@tonic-gate if (!$first_time) { 319*0Sstevel@tonic-gate $ok = 0; 320*0Sstevel@tonic-gate last TEST12; 321*0Sstevel@tonic-gate } 322*0Sstevel@tonic-gate $ok = 0; 323*0Sstevel@tonic-gate $first_time = 0; 324*0Sstevel@tonic-gate last; 325*0Sstevel@tonic-gate last TEST12; 326*0Sstevel@tonic-gate } 327*0Sstevel@tonic-gate continue { 328*0Sstevel@tonic-gate $ok=0; 329*0Sstevel@tonic-gate last TEST12; 330*0Sstevel@tonic-gate } 331*0Sstevel@tonic-gate $ok = 1; 332*0Sstevel@tonic-gate} 333*0Sstevel@tonic-gateprint ($ok ? "ok 12\n" : "not ok 12\n"); 334*0Sstevel@tonic-gate 335*0Sstevel@tonic-gate## for(;;) loop without a label 336*0Sstevel@tonic-gate 337*0Sstevel@tonic-gateTEST13: { # redo 338*0Sstevel@tonic-gate 339*0Sstevel@tonic-gate $ok = 0; 340*0Sstevel@tonic-gate 341*0Sstevel@tonic-gate for(my $first_time = 1; 1;) { 342*0Sstevel@tonic-gate if (!$first_time) { 343*0Sstevel@tonic-gate $ok = 1; 344*0Sstevel@tonic-gate last TEST13; 345*0Sstevel@tonic-gate } 346*0Sstevel@tonic-gate $ok = 0; 347*0Sstevel@tonic-gate $first_time=0; 348*0Sstevel@tonic-gate 349*0Sstevel@tonic-gate redo; 350*0Sstevel@tonic-gate last TEST13; 351*0Sstevel@tonic-gate } 352*0Sstevel@tonic-gate $ok = 0; 353*0Sstevel@tonic-gate} 354*0Sstevel@tonic-gateprint ($ok ? "ok 13\n" : "not ok 13\n"); 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gateTEST14: { # next (successful) 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate $ok = 0; 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gate for(my $first_time = 1; 1; $first_time=0) { 361*0Sstevel@tonic-gate if (!$first_time) { 362*0Sstevel@tonic-gate $ok = 1; 363*0Sstevel@tonic-gate last TEST14; 364*0Sstevel@tonic-gate } 365*0Sstevel@tonic-gate $ok = 0; 366*0Sstevel@tonic-gate next; 367*0Sstevel@tonic-gate last TEST14; 368*0Sstevel@tonic-gate } 369*0Sstevel@tonic-gate $ok = 0; 370*0Sstevel@tonic-gate} 371*0Sstevel@tonic-gateprint ($ok ? "ok 14\n" : "not ok 14\n"); 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gateTEST15: { # next (unsuccesful) 374*0Sstevel@tonic-gate 375*0Sstevel@tonic-gate $ok = 0; 376*0Sstevel@tonic-gate 377*0Sstevel@tonic-gate my $x=1; 378*0Sstevel@tonic-gate my $been_in_loop = 0; 379*0Sstevel@tonic-gate for(my $first_time = 1; $x--;) { 380*0Sstevel@tonic-gate $been_in_loop = 1; 381*0Sstevel@tonic-gate if (!$first_time) { 382*0Sstevel@tonic-gate $ok = 0; 383*0Sstevel@tonic-gate last TEST15; 384*0Sstevel@tonic-gate } 385*0Sstevel@tonic-gate $ok = 0; 386*0Sstevel@tonic-gate $first_time = 0; 387*0Sstevel@tonic-gate next; 388*0Sstevel@tonic-gate last TEST15; 389*0Sstevel@tonic-gate } 390*0Sstevel@tonic-gate $ok = $been_in_loop; 391*0Sstevel@tonic-gate} 392*0Sstevel@tonic-gateprint ($ok ? "ok 15\n" : "not ok 15\n"); 393*0Sstevel@tonic-gate 394*0Sstevel@tonic-gateTEST16: { # last 395*0Sstevel@tonic-gate 396*0Sstevel@tonic-gate $ok = 0; 397*0Sstevel@tonic-gate 398*0Sstevel@tonic-gate for(my $first_time = 1; 1; last TEST16) { 399*0Sstevel@tonic-gate if (!$first_time) { 400*0Sstevel@tonic-gate $ok = 0; 401*0Sstevel@tonic-gate last TEST16; 402*0Sstevel@tonic-gate } 403*0Sstevel@tonic-gate $ok = 0; 404*0Sstevel@tonic-gate $first_time = 0; 405*0Sstevel@tonic-gate last; 406*0Sstevel@tonic-gate last TEST16; 407*0Sstevel@tonic-gate } 408*0Sstevel@tonic-gate $ok = 1; 409*0Sstevel@tonic-gate} 410*0Sstevel@tonic-gateprint ($ok ? "ok 16\n" : "not ok 16\n"); 411*0Sstevel@tonic-gate 412*0Sstevel@tonic-gate## bare block without a label 413*0Sstevel@tonic-gate 414*0Sstevel@tonic-gateTEST17: { # redo 415*0Sstevel@tonic-gate 416*0Sstevel@tonic-gate $ok = 0; 417*0Sstevel@tonic-gate my $first_time = 1; 418*0Sstevel@tonic-gate 419*0Sstevel@tonic-gate { 420*0Sstevel@tonic-gate if (!$first_time) { 421*0Sstevel@tonic-gate $ok = 1; 422*0Sstevel@tonic-gate last TEST17; 423*0Sstevel@tonic-gate } 424*0Sstevel@tonic-gate $ok = 0; 425*0Sstevel@tonic-gate $first_time=0; 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate redo; 428*0Sstevel@tonic-gate last TEST17; 429*0Sstevel@tonic-gate } 430*0Sstevel@tonic-gate continue { 431*0Sstevel@tonic-gate $ok = 0; 432*0Sstevel@tonic-gate last TEST17; 433*0Sstevel@tonic-gate } 434*0Sstevel@tonic-gate $ok = 0; 435*0Sstevel@tonic-gate} 436*0Sstevel@tonic-gateprint ($ok ? "ok 17\n" : "not ok 17\n"); 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gateTEST18: { # next 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate $ok = 0; 441*0Sstevel@tonic-gate { 442*0Sstevel@tonic-gate next; 443*0Sstevel@tonic-gate last TEST18; 444*0Sstevel@tonic-gate } 445*0Sstevel@tonic-gate continue { 446*0Sstevel@tonic-gate $ok = 1; 447*0Sstevel@tonic-gate last TEST18; 448*0Sstevel@tonic-gate } 449*0Sstevel@tonic-gate $ok = 0; 450*0Sstevel@tonic-gate} 451*0Sstevel@tonic-gateprint ($ok ? "ok 18\n" : "not ok 18\n"); 452*0Sstevel@tonic-gate 453*0Sstevel@tonic-gateTEST19: { # last 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate $ok = 0; 456*0Sstevel@tonic-gate { 457*0Sstevel@tonic-gate last; 458*0Sstevel@tonic-gate last TEST19; 459*0Sstevel@tonic-gate } 460*0Sstevel@tonic-gate continue { 461*0Sstevel@tonic-gate $ok = 0; 462*0Sstevel@tonic-gate last TEST19; 463*0Sstevel@tonic-gate } 464*0Sstevel@tonic-gate $ok = 1; 465*0Sstevel@tonic-gate} 466*0Sstevel@tonic-gateprint ($ok ? "ok 19\n" : "not ok 19\n"); 467*0Sstevel@tonic-gate 468*0Sstevel@tonic-gate 469*0Sstevel@tonic-gate### Now do it all again with labels 470*0Sstevel@tonic-gate 471*0Sstevel@tonic-gate## while() loop with a label 472*0Sstevel@tonic-gate 473*0Sstevel@tonic-gateTEST20: { # redo 474*0Sstevel@tonic-gate 475*0Sstevel@tonic-gate $ok = 0; 476*0Sstevel@tonic-gate 477*0Sstevel@tonic-gate my $x = 1; 478*0Sstevel@tonic-gate my $first_time = 1; 479*0Sstevel@tonic-gate LABEL20: while($x--) { 480*0Sstevel@tonic-gate if (!$first_time) { 481*0Sstevel@tonic-gate $ok = 1; 482*0Sstevel@tonic-gate last TEST20; 483*0Sstevel@tonic-gate } 484*0Sstevel@tonic-gate $ok = 0; 485*0Sstevel@tonic-gate $first_time = 0; 486*0Sstevel@tonic-gate redo LABEL20; 487*0Sstevel@tonic-gate last TEST20; 488*0Sstevel@tonic-gate } 489*0Sstevel@tonic-gate continue { 490*0Sstevel@tonic-gate $ok = 0; 491*0Sstevel@tonic-gate last TEST20; 492*0Sstevel@tonic-gate } 493*0Sstevel@tonic-gate $ok = 0; 494*0Sstevel@tonic-gate} 495*0Sstevel@tonic-gateprint ($ok ? "ok 20\n" : "not ok 20\n"); 496*0Sstevel@tonic-gate 497*0Sstevel@tonic-gateTEST21: { # next (succesful) 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gate $ok = 0; 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gate my $x = 2; 502*0Sstevel@tonic-gate my $first_time = 1; 503*0Sstevel@tonic-gate my $been_in_continue = 0; 504*0Sstevel@tonic-gate LABEL21: while($x--) { 505*0Sstevel@tonic-gate if (!$first_time) { 506*0Sstevel@tonic-gate $ok = $been_in_continue; 507*0Sstevel@tonic-gate last TEST21; 508*0Sstevel@tonic-gate } 509*0Sstevel@tonic-gate $ok = 0; 510*0Sstevel@tonic-gate $first_time = 0; 511*0Sstevel@tonic-gate next LABEL21; 512*0Sstevel@tonic-gate last TEST21; 513*0Sstevel@tonic-gate } 514*0Sstevel@tonic-gate continue { 515*0Sstevel@tonic-gate $been_in_continue = 1; 516*0Sstevel@tonic-gate } 517*0Sstevel@tonic-gate $ok = 0; 518*0Sstevel@tonic-gate} 519*0Sstevel@tonic-gateprint ($ok ? "ok 21\n" : "not ok 21\n"); 520*0Sstevel@tonic-gate 521*0Sstevel@tonic-gateTEST22: { # next (unsuccesful) 522*0Sstevel@tonic-gate 523*0Sstevel@tonic-gate $ok = 0; 524*0Sstevel@tonic-gate 525*0Sstevel@tonic-gate my $x = 1; 526*0Sstevel@tonic-gate my $first_time = 1; 527*0Sstevel@tonic-gate my $been_in_loop = 0; 528*0Sstevel@tonic-gate my $been_in_continue = 0; 529*0Sstevel@tonic-gate LABEL22: while($x--) { 530*0Sstevel@tonic-gate $been_in_loop = 1; 531*0Sstevel@tonic-gate if (!$first_time) { 532*0Sstevel@tonic-gate $ok = 0; 533*0Sstevel@tonic-gate last TEST22; 534*0Sstevel@tonic-gate } 535*0Sstevel@tonic-gate $ok = 0; 536*0Sstevel@tonic-gate $first_time = 0; 537*0Sstevel@tonic-gate next LABEL22; 538*0Sstevel@tonic-gate last TEST22; 539*0Sstevel@tonic-gate } 540*0Sstevel@tonic-gate continue { 541*0Sstevel@tonic-gate $been_in_continue = 1; 542*0Sstevel@tonic-gate } 543*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 544*0Sstevel@tonic-gate} 545*0Sstevel@tonic-gateprint ($ok ? "ok 22\n" : "not ok 22\n"); 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gateTEST23: { # last 548*0Sstevel@tonic-gate 549*0Sstevel@tonic-gate $ok = 0; 550*0Sstevel@tonic-gate 551*0Sstevel@tonic-gate my $x = 1; 552*0Sstevel@tonic-gate my $first_time = 1; 553*0Sstevel@tonic-gate LABEL23: while($x++) { 554*0Sstevel@tonic-gate if (!$first_time) { 555*0Sstevel@tonic-gate $ok = 0; 556*0Sstevel@tonic-gate last TEST23; 557*0Sstevel@tonic-gate } 558*0Sstevel@tonic-gate $ok = 0; 559*0Sstevel@tonic-gate $first_time = 0; 560*0Sstevel@tonic-gate last LABEL23; 561*0Sstevel@tonic-gate last TEST23; 562*0Sstevel@tonic-gate } 563*0Sstevel@tonic-gate continue { 564*0Sstevel@tonic-gate $ok = 0; 565*0Sstevel@tonic-gate last TEST23; 566*0Sstevel@tonic-gate } 567*0Sstevel@tonic-gate $ok = 1; 568*0Sstevel@tonic-gate} 569*0Sstevel@tonic-gateprint ($ok ? "ok 23\n" : "not ok 23\n"); 570*0Sstevel@tonic-gate 571*0Sstevel@tonic-gate 572*0Sstevel@tonic-gate## until() loop with a label 573*0Sstevel@tonic-gate 574*0Sstevel@tonic-gateTEST24: { # redo 575*0Sstevel@tonic-gate 576*0Sstevel@tonic-gate $ok = 0; 577*0Sstevel@tonic-gate 578*0Sstevel@tonic-gate my $x = 0; 579*0Sstevel@tonic-gate my $first_time = 1; 580*0Sstevel@tonic-gate LABEL24: until($x++) { 581*0Sstevel@tonic-gate if (!$first_time) { 582*0Sstevel@tonic-gate $ok = 1; 583*0Sstevel@tonic-gate last TEST24; 584*0Sstevel@tonic-gate } 585*0Sstevel@tonic-gate $ok = 0; 586*0Sstevel@tonic-gate $first_time = 0; 587*0Sstevel@tonic-gate redo LABEL24; 588*0Sstevel@tonic-gate last TEST24; 589*0Sstevel@tonic-gate } 590*0Sstevel@tonic-gate continue { 591*0Sstevel@tonic-gate $ok = 0; 592*0Sstevel@tonic-gate last TEST24; 593*0Sstevel@tonic-gate } 594*0Sstevel@tonic-gate $ok = 0; 595*0Sstevel@tonic-gate} 596*0Sstevel@tonic-gateprint ($ok ? "ok 24\n" : "not ok 24\n"); 597*0Sstevel@tonic-gate 598*0Sstevel@tonic-gateTEST25: { # next (succesful) 599*0Sstevel@tonic-gate 600*0Sstevel@tonic-gate $ok = 0; 601*0Sstevel@tonic-gate 602*0Sstevel@tonic-gate my $x = 0; 603*0Sstevel@tonic-gate my $first_time = 1; 604*0Sstevel@tonic-gate my $been_in_continue = 0; 605*0Sstevel@tonic-gate LABEL25: until($x++ >= 2) { 606*0Sstevel@tonic-gate if (!$first_time) { 607*0Sstevel@tonic-gate $ok = $been_in_continue; 608*0Sstevel@tonic-gate last TEST25; 609*0Sstevel@tonic-gate } 610*0Sstevel@tonic-gate $ok = 0; 611*0Sstevel@tonic-gate $first_time = 0; 612*0Sstevel@tonic-gate next LABEL25; 613*0Sstevel@tonic-gate last TEST25; 614*0Sstevel@tonic-gate } 615*0Sstevel@tonic-gate continue { 616*0Sstevel@tonic-gate $been_in_continue = 1; 617*0Sstevel@tonic-gate } 618*0Sstevel@tonic-gate $ok = 0; 619*0Sstevel@tonic-gate} 620*0Sstevel@tonic-gateprint ($ok ? "ok 25\n" : "not ok 25\n"); 621*0Sstevel@tonic-gate 622*0Sstevel@tonic-gateTEST26: { # next (unsuccesful) 623*0Sstevel@tonic-gate 624*0Sstevel@tonic-gate $ok = 0; 625*0Sstevel@tonic-gate 626*0Sstevel@tonic-gate my $x = 0; 627*0Sstevel@tonic-gate my $first_time = 1; 628*0Sstevel@tonic-gate my $been_in_loop = 0; 629*0Sstevel@tonic-gate my $been_in_continue = 0; 630*0Sstevel@tonic-gate LABEL26: until($x++) { 631*0Sstevel@tonic-gate $been_in_loop = 1; 632*0Sstevel@tonic-gate if (!$first_time) { 633*0Sstevel@tonic-gate $ok = 0; 634*0Sstevel@tonic-gate last TEST26; 635*0Sstevel@tonic-gate } 636*0Sstevel@tonic-gate $ok = 0; 637*0Sstevel@tonic-gate $first_time = 0; 638*0Sstevel@tonic-gate next LABEL26; 639*0Sstevel@tonic-gate last TEST26; 640*0Sstevel@tonic-gate } 641*0Sstevel@tonic-gate continue { 642*0Sstevel@tonic-gate $been_in_continue = 1; 643*0Sstevel@tonic-gate } 644*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 645*0Sstevel@tonic-gate} 646*0Sstevel@tonic-gateprint ($ok ? "ok 26\n" : "not ok 26\n"); 647*0Sstevel@tonic-gate 648*0Sstevel@tonic-gateTEST27: { # last 649*0Sstevel@tonic-gate 650*0Sstevel@tonic-gate $ok = 0; 651*0Sstevel@tonic-gate 652*0Sstevel@tonic-gate my $x = 0; 653*0Sstevel@tonic-gate my $first_time = 1; 654*0Sstevel@tonic-gate LABEL27: until($x++ == 10) { 655*0Sstevel@tonic-gate if (!$first_time) { 656*0Sstevel@tonic-gate $ok = 0; 657*0Sstevel@tonic-gate last TEST27; 658*0Sstevel@tonic-gate } 659*0Sstevel@tonic-gate $ok = 0; 660*0Sstevel@tonic-gate $first_time = 0; 661*0Sstevel@tonic-gate last LABEL27; 662*0Sstevel@tonic-gate last TEST27; 663*0Sstevel@tonic-gate } 664*0Sstevel@tonic-gate continue { 665*0Sstevel@tonic-gate $ok = 0; 666*0Sstevel@tonic-gate last TEST8; 667*0Sstevel@tonic-gate } 668*0Sstevel@tonic-gate $ok = 1; 669*0Sstevel@tonic-gate} 670*0Sstevel@tonic-gateprint ($ok ? "ok 27\n" : "not ok 27\n"); 671*0Sstevel@tonic-gate 672*0Sstevel@tonic-gate## for(@array) loop with a label 673*0Sstevel@tonic-gate 674*0Sstevel@tonic-gateTEST28: { # redo 675*0Sstevel@tonic-gate 676*0Sstevel@tonic-gate $ok = 0; 677*0Sstevel@tonic-gate 678*0Sstevel@tonic-gate my $first_time = 1; 679*0Sstevel@tonic-gate LABEL28: for(1) { 680*0Sstevel@tonic-gate if (!$first_time) { 681*0Sstevel@tonic-gate $ok = 1; 682*0Sstevel@tonic-gate last TEST28; 683*0Sstevel@tonic-gate } 684*0Sstevel@tonic-gate $ok = 0; 685*0Sstevel@tonic-gate $first_time = 0; 686*0Sstevel@tonic-gate redo LABEL28; 687*0Sstevel@tonic-gate last TEST28; 688*0Sstevel@tonic-gate } 689*0Sstevel@tonic-gate continue { 690*0Sstevel@tonic-gate $ok = 0; 691*0Sstevel@tonic-gate last TEST28; 692*0Sstevel@tonic-gate } 693*0Sstevel@tonic-gate $ok = 0; 694*0Sstevel@tonic-gate} 695*0Sstevel@tonic-gateprint ($ok ? "ok 28\n" : "not ok 28\n"); 696*0Sstevel@tonic-gate 697*0Sstevel@tonic-gateTEST29: { # next (succesful) 698*0Sstevel@tonic-gate 699*0Sstevel@tonic-gate $ok = 0; 700*0Sstevel@tonic-gate 701*0Sstevel@tonic-gate my $first_time = 1; 702*0Sstevel@tonic-gate my $been_in_continue = 0; 703*0Sstevel@tonic-gate LABEL29: for(1,2) { 704*0Sstevel@tonic-gate if (!$first_time) { 705*0Sstevel@tonic-gate $ok = $been_in_continue; 706*0Sstevel@tonic-gate last TEST29; 707*0Sstevel@tonic-gate } 708*0Sstevel@tonic-gate $ok = 0; 709*0Sstevel@tonic-gate $first_time = 0; 710*0Sstevel@tonic-gate next LABEL29; 711*0Sstevel@tonic-gate last TEST29; 712*0Sstevel@tonic-gate } 713*0Sstevel@tonic-gate continue { 714*0Sstevel@tonic-gate $been_in_continue = 1; 715*0Sstevel@tonic-gate } 716*0Sstevel@tonic-gate $ok = 0; 717*0Sstevel@tonic-gate} 718*0Sstevel@tonic-gateprint ($ok ? "ok 29\n" : "not ok 29\n"); 719*0Sstevel@tonic-gate 720*0Sstevel@tonic-gateTEST30: { # next (unsuccesful) 721*0Sstevel@tonic-gate 722*0Sstevel@tonic-gate $ok = 0; 723*0Sstevel@tonic-gate 724*0Sstevel@tonic-gate my $first_time = 1; 725*0Sstevel@tonic-gate my $been_in_loop = 0; 726*0Sstevel@tonic-gate my $been_in_continue = 0; 727*0Sstevel@tonic-gate LABEL30: for(1) { 728*0Sstevel@tonic-gate $been_in_loop = 1; 729*0Sstevel@tonic-gate if (!$first_time) { 730*0Sstevel@tonic-gate $ok = 0; 731*0Sstevel@tonic-gate last TEST30; 732*0Sstevel@tonic-gate } 733*0Sstevel@tonic-gate $ok = 0; 734*0Sstevel@tonic-gate $first_time = 0; 735*0Sstevel@tonic-gate next LABEL30; 736*0Sstevel@tonic-gate last TEST30; 737*0Sstevel@tonic-gate } 738*0Sstevel@tonic-gate continue { 739*0Sstevel@tonic-gate $been_in_continue = 1; 740*0Sstevel@tonic-gate } 741*0Sstevel@tonic-gate $ok = $been_in_loop && $been_in_continue; 742*0Sstevel@tonic-gate} 743*0Sstevel@tonic-gateprint ($ok ? "ok 30\n" : "not ok 30\n"); 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gateTEST31: { # last 746*0Sstevel@tonic-gate 747*0Sstevel@tonic-gate $ok = 0; 748*0Sstevel@tonic-gate 749*0Sstevel@tonic-gate my $first_time = 1; 750*0Sstevel@tonic-gate LABEL31: for(1..10) { 751*0Sstevel@tonic-gate if (!$first_time) { 752*0Sstevel@tonic-gate $ok = 0; 753*0Sstevel@tonic-gate last TEST31; 754*0Sstevel@tonic-gate } 755*0Sstevel@tonic-gate $ok = 0; 756*0Sstevel@tonic-gate $first_time = 0; 757*0Sstevel@tonic-gate last LABEL31; 758*0Sstevel@tonic-gate last TEST31; 759*0Sstevel@tonic-gate } 760*0Sstevel@tonic-gate continue { 761*0Sstevel@tonic-gate $ok=0; 762*0Sstevel@tonic-gate last TEST31; 763*0Sstevel@tonic-gate } 764*0Sstevel@tonic-gate $ok = 1; 765*0Sstevel@tonic-gate} 766*0Sstevel@tonic-gateprint ($ok ? "ok 31\n" : "not ok 31\n"); 767*0Sstevel@tonic-gate 768*0Sstevel@tonic-gate## for(;;) loop with a label 769*0Sstevel@tonic-gate 770*0Sstevel@tonic-gateTEST32: { # redo 771*0Sstevel@tonic-gate 772*0Sstevel@tonic-gate $ok = 0; 773*0Sstevel@tonic-gate 774*0Sstevel@tonic-gate LABEL32: for(my $first_time = 1; 1;) { 775*0Sstevel@tonic-gate if (!$first_time) { 776*0Sstevel@tonic-gate $ok = 1; 777*0Sstevel@tonic-gate last TEST32; 778*0Sstevel@tonic-gate } 779*0Sstevel@tonic-gate $ok = 0; 780*0Sstevel@tonic-gate $first_time=0; 781*0Sstevel@tonic-gate 782*0Sstevel@tonic-gate redo LABEL32; 783*0Sstevel@tonic-gate last TEST32; 784*0Sstevel@tonic-gate } 785*0Sstevel@tonic-gate $ok = 0; 786*0Sstevel@tonic-gate} 787*0Sstevel@tonic-gateprint ($ok ? "ok 32\n" : "not ok 32\n"); 788*0Sstevel@tonic-gate 789*0Sstevel@tonic-gateTEST33: { # next (successful) 790*0Sstevel@tonic-gate 791*0Sstevel@tonic-gate $ok = 0; 792*0Sstevel@tonic-gate 793*0Sstevel@tonic-gate LABEL33: for(my $first_time = 1; 1; $first_time=0) { 794*0Sstevel@tonic-gate if (!$first_time) { 795*0Sstevel@tonic-gate $ok = 1; 796*0Sstevel@tonic-gate last TEST33; 797*0Sstevel@tonic-gate } 798*0Sstevel@tonic-gate $ok = 0; 799*0Sstevel@tonic-gate next LABEL33; 800*0Sstevel@tonic-gate last TEST33; 801*0Sstevel@tonic-gate } 802*0Sstevel@tonic-gate $ok = 0; 803*0Sstevel@tonic-gate} 804*0Sstevel@tonic-gateprint ($ok ? "ok 33\n" : "not ok 33\n"); 805*0Sstevel@tonic-gate 806*0Sstevel@tonic-gateTEST34: { # next (unsuccesful) 807*0Sstevel@tonic-gate 808*0Sstevel@tonic-gate $ok = 0; 809*0Sstevel@tonic-gate 810*0Sstevel@tonic-gate my $x=1; 811*0Sstevel@tonic-gate my $been_in_loop = 0; 812*0Sstevel@tonic-gate LABEL34: for(my $first_time = 1; $x--;) { 813*0Sstevel@tonic-gate $been_in_loop = 1; 814*0Sstevel@tonic-gate if (!$first_time) { 815*0Sstevel@tonic-gate $ok = 0; 816*0Sstevel@tonic-gate last TEST34; 817*0Sstevel@tonic-gate } 818*0Sstevel@tonic-gate $ok = 0; 819*0Sstevel@tonic-gate $first_time = 0; 820*0Sstevel@tonic-gate next LABEL34; 821*0Sstevel@tonic-gate last TEST34; 822*0Sstevel@tonic-gate } 823*0Sstevel@tonic-gate $ok = $been_in_loop; 824*0Sstevel@tonic-gate} 825*0Sstevel@tonic-gateprint ($ok ? "ok 34\n" : "not ok 34\n"); 826*0Sstevel@tonic-gate 827*0Sstevel@tonic-gateTEST35: { # last 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate $ok = 0; 830*0Sstevel@tonic-gate 831*0Sstevel@tonic-gate LABEL35: for(my $first_time = 1; 1; last TEST16) { 832*0Sstevel@tonic-gate if (!$first_time) { 833*0Sstevel@tonic-gate $ok = 0; 834*0Sstevel@tonic-gate last TEST35; 835*0Sstevel@tonic-gate } 836*0Sstevel@tonic-gate $ok = 0; 837*0Sstevel@tonic-gate $first_time = 0; 838*0Sstevel@tonic-gate last LABEL35; 839*0Sstevel@tonic-gate last TEST35; 840*0Sstevel@tonic-gate } 841*0Sstevel@tonic-gate $ok = 1; 842*0Sstevel@tonic-gate} 843*0Sstevel@tonic-gateprint ($ok ? "ok 35\n" : "not ok 35\n"); 844*0Sstevel@tonic-gate 845*0Sstevel@tonic-gate## bare block with a label 846*0Sstevel@tonic-gate 847*0Sstevel@tonic-gateTEST36: { # redo 848*0Sstevel@tonic-gate 849*0Sstevel@tonic-gate $ok = 0; 850*0Sstevel@tonic-gate my $first_time = 1; 851*0Sstevel@tonic-gate 852*0Sstevel@tonic-gate LABEL36: { 853*0Sstevel@tonic-gate if (!$first_time) { 854*0Sstevel@tonic-gate $ok = 1; 855*0Sstevel@tonic-gate last TEST36; 856*0Sstevel@tonic-gate } 857*0Sstevel@tonic-gate $ok = 0; 858*0Sstevel@tonic-gate $first_time=0; 859*0Sstevel@tonic-gate 860*0Sstevel@tonic-gate redo LABEL36; 861*0Sstevel@tonic-gate last TEST36; 862*0Sstevel@tonic-gate } 863*0Sstevel@tonic-gate continue { 864*0Sstevel@tonic-gate $ok = 0; 865*0Sstevel@tonic-gate last TEST36; 866*0Sstevel@tonic-gate } 867*0Sstevel@tonic-gate $ok = 0; 868*0Sstevel@tonic-gate} 869*0Sstevel@tonic-gateprint ($ok ? "ok 36\n" : "not ok 36\n"); 870*0Sstevel@tonic-gate 871*0Sstevel@tonic-gateTEST37: { # next 872*0Sstevel@tonic-gate 873*0Sstevel@tonic-gate $ok = 0; 874*0Sstevel@tonic-gate LABEL37: { 875*0Sstevel@tonic-gate next LABEL37; 876*0Sstevel@tonic-gate last TEST37; 877*0Sstevel@tonic-gate } 878*0Sstevel@tonic-gate continue { 879*0Sstevel@tonic-gate $ok = 1; 880*0Sstevel@tonic-gate last TEST37; 881*0Sstevel@tonic-gate } 882*0Sstevel@tonic-gate $ok = 0; 883*0Sstevel@tonic-gate} 884*0Sstevel@tonic-gateprint ($ok ? "ok 37\n" : "not ok 37\n"); 885*0Sstevel@tonic-gate 886*0Sstevel@tonic-gateTEST38: { # last 887*0Sstevel@tonic-gate 888*0Sstevel@tonic-gate $ok = 0; 889*0Sstevel@tonic-gate LABEL38: { 890*0Sstevel@tonic-gate last LABEL38; 891*0Sstevel@tonic-gate last TEST38; 892*0Sstevel@tonic-gate } 893*0Sstevel@tonic-gate continue { 894*0Sstevel@tonic-gate $ok = 0; 895*0Sstevel@tonic-gate last TEST38; 896*0Sstevel@tonic-gate } 897*0Sstevel@tonic-gate $ok = 1; 898*0Sstevel@tonic-gate} 899*0Sstevel@tonic-gateprint ($ok ? "ok 38\n" : "not ok 38\n"); 900*0Sstevel@tonic-gate 901*0Sstevel@tonic-gate### Now test nested constructs 902*0Sstevel@tonic-gate 903*0Sstevel@tonic-gateTEST39: { 904*0Sstevel@tonic-gate $ok = 0; 905*0Sstevel@tonic-gate my ($x, $y, $z) = (1,1,1); 906*0Sstevel@tonic-gate one39: while ($x--) { 907*0Sstevel@tonic-gate $ok = 0; 908*0Sstevel@tonic-gate two39: while ($y--) { 909*0Sstevel@tonic-gate $ok = 0; 910*0Sstevel@tonic-gate three39: while ($z--) { 911*0Sstevel@tonic-gate next two39; 912*0Sstevel@tonic-gate } 913*0Sstevel@tonic-gate continue { 914*0Sstevel@tonic-gate $ok = 0; 915*0Sstevel@tonic-gate last TEST39; 916*0Sstevel@tonic-gate } 917*0Sstevel@tonic-gate } 918*0Sstevel@tonic-gate continue { 919*0Sstevel@tonic-gate $ok = 1; 920*0Sstevel@tonic-gate last TEST39; 921*0Sstevel@tonic-gate } 922*0Sstevel@tonic-gate $ok = 0; 923*0Sstevel@tonic-gate } 924*0Sstevel@tonic-gate} 925*0Sstevel@tonic-gateprint ($ok ? "ok 39\n" : "not ok 39\n"); 926*0Sstevel@tonic-gate 927*0Sstevel@tonic-gate 928*0Sstevel@tonic-gate### Test that loop control is dynamicly scoped. 929*0Sstevel@tonic-gate 930*0Sstevel@tonic-gatesub test_last_label { last TEST40 } 931*0Sstevel@tonic-gate 932*0Sstevel@tonic-gateTEST40: { 933*0Sstevel@tonic-gate $ok = 1; 934*0Sstevel@tonic-gate test_last_label(); 935*0Sstevel@tonic-gate $ok = 0; 936*0Sstevel@tonic-gate} 937*0Sstevel@tonic-gateprint ($ok ? "ok 40\n" : "not ok 40\n"); 938*0Sstevel@tonic-gate 939*0Sstevel@tonic-gatesub test_last { last } 940*0Sstevel@tonic-gate 941*0Sstevel@tonic-gateTEST41: { 942*0Sstevel@tonic-gate $ok = 1; 943*0Sstevel@tonic-gate test_last(); 944*0Sstevel@tonic-gate $ok = 0; 945*0Sstevel@tonic-gate} 946*0Sstevel@tonic-gateprint ($ok ? "ok 41\n" : "not ok 41\n"); 947*0Sstevel@tonic-gate 948*0Sstevel@tonic-gate 949*0Sstevel@tonic-gate# [perl #27206] Memory leak in continue loop 950*0Sstevel@tonic-gate# Ensure that the temporary object is freed each time round the loop, 951*0Sstevel@tonic-gate# rather then all 10 of them all being freed right at the end 952*0Sstevel@tonic-gate 953*0Sstevel@tonic-gate{ 954*0Sstevel@tonic-gate my $n=10; my $late_free = 0; 955*0Sstevel@tonic-gate sub X::DESTROY { $late_free++ if $n < 0 }; 956*0Sstevel@tonic-gate { 957*0Sstevel@tonic-gate ($n-- && bless {}, 'X') && redo; 958*0Sstevel@tonic-gate } 959*0Sstevel@tonic-gate print $late_free ? "not " : "", "ok 42 - redo memory leak\n"; 960*0Sstevel@tonic-gate 961*0Sstevel@tonic-gate $n = 10; $late_free = 0; 962*0Sstevel@tonic-gate { 963*0Sstevel@tonic-gate ($n-- && bless {}, 'X') && redo; 964*0Sstevel@tonic-gate } 965*0Sstevel@tonic-gate continue { } 966*0Sstevel@tonic-gate print $late_free ? "not " : "", "ok 43 - redo with continue memory leak\n"; 967*0Sstevel@tonic-gate} 968*0Sstevel@tonic-gate 969*0Sstevel@tonic-gate 970