Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > d92aa75c2d384ff9f513aed09a46f703 > files > 847

parrot-doc-3.1.0-2.mga1.i586.rpm

# Copyright (C) 2007-2009, Parrot Foundation.

=head1 Loops

PIR has no built-in looping structures such as C<for>, C<while>,
C<repeat> or C<until>. All loops are built by using conditionals
and C<goto>.

The loop below calculates 5 factorial, stored in C<$I0>.  C<$I1>
is the loop counter. In each loop iteration we decrement the counter
to see if we've done the loop enough times. The conditional jump
moves control flow back to the top of the loop if more iterations
are needed.

=cut

.sub main :main

    $I0 = 1               # product
    $I1 = 5               # counter

  REDO:                   # start of loop
    $I0 = $I0 * $I1
    dec $I1               # decrement counter
    if $I1 > 0 goto REDO  # end of loop

    print $I0
    print "\n"

.end

# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: