Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do-while bug #960

Closed
p5pRT opened this issue Dec 16, 1999 · 2 comments
Closed

do-while bug #960

p5pRT opened this issue Dec 16, 1999 · 2 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 16, 1999

Migrated from rt.perl.org#1907 (status was 'resolved')

Searchable as RT1907$

@p5pRT
Copy link
Author

p5pRT commented Dec 16, 1999

From clewis@apollosolutions.com

I found a bug, or at least unexpected operation, from the last operator
inside a
do-while loop.

% perl -v

This is perl, version 5.005_03 built for i386-linux

Copyright 1987-1999, Larry Wall

Perl may be copied only under the terms of either the Artistic License
or the
GNU General Public License, which may be found in the Perl 5.0 source
kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to
the
Internet, point your browser at http​://www.perl.com/, the Perl Home
Page.

I wrote some test code which demonstrates my unexpected output​:

----- Begin test_dowhile.pl -----
#!/usr/bin/perl

print "Before For Loop.\n";
for( $i=0; $i<2; $i++)
{
  print " For loop iteration ", $i, "\n";
  $j=0;
  print " Before do-while loop.\n";
  do
  {
  print " Do-while iteration ", $j, "\n";
  last if $j>1;
  $j++;
  } while( $j < 10);
  print " After do-while loop.\n";
}
print "After For Loop.\n";
----- End test_dowhile.pl -----

I expected the following output​:

Before For Loop.
  For loop iteration 0
  Before do-while loop.
  Do-while iteration 0
  Do-while iteration 1
  Do-while iteration 2
  After do-while loop.
  For loop iteration 1
  Before do-while loop.
  Do-while iteration 0
  Do-while iteration 1
  Do-while iteration 2
  After do-while loop.
After For Loop.

Instead, I got​:
Before For Loop.
  For loop iteration 0
  Before do-while loop.
  Do-while iteration 0
  Do-while iteration 1
  Do-while iteration 2
After For Loop.

It appears that the "last" operator does not consider do-while a loop,
and therefore exits
the parent loop. I've already re-written my code to use a for() loop,
and most people
don't use do-while's, so this is probably a low priority.

--
Craig Lewis CLewis@​ApolloSolutions.Com
-----BEGIN GEEK CODE BLOCK-----
Version​: 3.12
GE/CS d- s​:+ a--@​ C++$ UL++++$ P+++$ L+++(++) E--- W+++$ N+ o K w-- O M-
V-
PS+ PE+(-) Y+ PGP- t 5 X+ R tv b++(++++) DI+ D+ G+ e++>* h--- r+++ y+++
------END GEEK CODE BLOCK------

@p5pRT
Copy link
Author

p5pRT commented Dec 16, 1999

From @tamias

On Thu, Dec 16, 1999 at 02​:06​:38PM -0600, Craig Lewis wrote​:

I did a quick search of the PerlBug Database, but I didn't find anything
that seems
related.

I found a bug, or at least unexpected operation, from the last operator
inside a
do-while loop.

As documented. perldoc -f last

  last cannot be used to exit a block which returns a value such as
  eval {}, sub {} or do {}, and should not be used to exit
  a grep() or map() operation.

Ronald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant