xref: /openbsd-src/gnu/usr.bin/perl/t/base/while.t (revision 898184e3e61f9129feb5978fad5a8c6865f00b92)
1*898184e3Ssthen#!./perl
2*898184e3Ssthen
3*898184e3Ssthenprint "1..4\n";
4*898184e3Ssthen
5*898184e3Ssthen# very basic tests of while
6*898184e3Ssthen
7*898184e3Ssthen$x = 0;
8*898184e3Ssthenwhile ($x != 3) {
9*898184e3Ssthen    $x = $x + 1;
10*898184e3Ssthen}
11*898184e3Ssthenif ($x == 3) { print "ok 1\n"; } else { print "not ok 1\n";}
12*898184e3Ssthen
13*898184e3Ssthen$x = 0;
14*898184e3Ssthenwhile (1) {
15*898184e3Ssthen    $x = $x + 1;
16*898184e3Ssthen    last if $x == 3;
17*898184e3Ssthen}
18*898184e3Ssthenif ($x == 3) { print "ok 2\n"; } else { print "not ok 2\n";}
19*898184e3Ssthen
20*898184e3Ssthen$x = 0;
21*898184e3Ssthenwhile ($x != 3) {
22*898184e3Ssthen    $x = $x + 1;
23*898184e3Ssthen    next;
24*898184e3Ssthen    print "not ";
25*898184e3Ssthen}
26*898184e3Ssthenprint "ok 3\n";
27*898184e3Ssthen
28*898184e3Ssthen$x = 0;
29*898184e3Ssthenwhile (0) {
30*898184e3Ssthen    $x = 1;
31*898184e3Ssthen}
32*898184e3Ssthenif ($x == 0) { print "ok 4\n"; } else { print "not ok 4\n";}
33*898184e3Ssthen
34