The void context means that you're doing something that does nothing useful.

$num * 3;

Takes the value of $num, multiplies it by 3 and then trows the result 
away, leaving $num unchanged.  I think you want *=  like this:

use strict;

print "Please type an integer: ";
chomp( my $num = <STDIN> );
while($num != 1){
   print "$num, ";
   if( 0 == ($num % 2) ){
       $num /= 2;
   } else {
       num *= 3;
       ++num;
   }
}
print "$num\n";

This will give you the output:

Please type and integer: 35
35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1

Its a cute little math trick.

By the way omitting the '\n' on the last print probably won't look too 
different if you're on windoze.  Its outside the loop and only affects 
the final print.  I put commas in to show what the other print is doing.

- Johnathan

Reply via email to