in reply to using redo in an if/else statement

I was trying to reply this post, but then...I myself become really confused.

I first wrote "redo works with all 'iterators', like for, while, do", then I started to coding and test, however I was stuck with this piece of code:
use strict; my $i = 1; my $flag = 1; do { print "$i "; if (($i ++ == 5) && $flag) { $flag = !$flag; #redo; } } until ($i >= 10);
If I uncomment that redo, perl gave me "can't redo outside a loop block". (Perl was fine with for and while)

Did I miss something obvious, or that is just the way perl goes, (if that is the way perl goes, I don't buy their logic at all, "do {} unitl" is not a loop?)

Replies are listed 'Best First'.
Re: Re: using redo in an if/else statement
by gjb (Vicar) on Jan 14, 2003 at 21:58 UTC

    I was bitten by that one too a while ago. do {...} until (...); looks like a loop but isn't one since until plays the role of a modifier and isn't a statement. Have a look at this for official confirmation.

    Hope this helps, -gjb-