codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  strange Perl loop  gamelion at 09:10 on Sunday, July 23, 2006
 

Hi, there,
I wrote such a short code

$count=10;
while($count--){print "$count\n";}

my expected output is "10 9 8 7 6 5 4 3 2 1",
however, its real output is "9 8 7 6 5 4 3 2 1 0".

any explaination?
thanks.



  Re: strange Perl loop  javabits at 08:05 on Friday, August 11, 2006
 

not really that strange.

the first time through the loop

while($count--) # count evaluates to 10 and is decremented to 9
{
print "$count\n"; # count is 9 because you just decremented
}

semper fi...








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  static asp url by 404 custom error code for Search Engine
•  Newbie needs Help
•  Need expertise - converting
•  Re: link spider
•  Re: Yahoo Tabbed menu control
•  Re: Insert Contents of .txt file into a .html page
•  Re: strange Perl loop
•  Re: need help writing a simple perl script
•  Pass a variable to open popup window w/o forms


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006