Quick Perl question: when going through a loop (say a while loop), what is the difference between a next and continue command? I thought both just skip to the next iteration of the loop.
Quick Perl question: when going through a loop (say a while loop), what is
Share
The
continuekeyword can be used after the block of a loop. The code in thecontinueblock is executed before the next iteration (before the loop condition is evaluated). It does not affect the control-flow.Is almost equivalent to
The
continuekeyword has another meaning in thegiven–whenconstruct, Perl’sswitch–case. After awhenblock is executed, Perl automaticallybreaks because most programs do that anyway. If you want to fall through to the next cases thecontinuehas to be used. Here,continuemodifies the control flow.Will print
The
nextkeyword is only available in loops and causes a new iteration incl. re-evaluation of the loop condition.redojumps to the beginning of a loop block. The loop condition is not evaluated.