Greetings,
This unenlightened neophyte finds that this problem is beyond his humble 
understanding and seeks guidance from those more wise in the mysterious 
ways of Perl. The following short program was offered for this one's 
edification but proves beyond his grasp.

#1/usr/bin/perl  -w
#exercise 3.7, take first input and raise it to the power of the second 
input

$i = 1;
$power = 1;

print "Input a number:\n";
chomp ( $x = <STDIN> );

print "Input the value you want the number raised to\n";
chomp ( $y = <STDIN>) ;
        
while ( $i<= $y ) {
        $power *= $x;
        ++ $i;
}
print "The result is $power.\n";


This one see how:
if ( $y>= 1 ){
  $power =  $x ** $y;
}
would work. The conditional is a simple algebraic expression. Yet, his 
vision fails when that conditional is equivalent to:

while ( $i<= $y ) {
        $power *= $x;
        ++ $i;
}
How does $y interact with $power? How does incrementing $i satisfy the 
while condition and not lead into a large loop? Is this one even asking 
the most useful questions? Edification would be most greatly 
appreciated.   michael

Reply via email to