Re: converting while loop to a for loop

2008-12-01 Thread John W. Krahn
dippa wrote: basic perl problem which is annoying me, the code is: --- #!/usr/bin/perl -w use strict; my $string; my $subString; my @indexes; print "Enter a string:\n"; chomp($string = ); print "\nEnter substring to search for:\n"; chomp($subString = ); ## This while loop does what i'm after

Re: converting while loop to a for loop

2008-12-01 Thread Rob Dixon
dippa wrote: > > Trying to work out why: > 1. the for loop does not work, want the same logic as the while loop > 2. for(my $pos = -1; $pos == -1; $pos++) only iterates through once > 3. for(my $pos = 0; $pos == -1; $pos++) does not enter loop at all Because in both cases your while condition

converting while loop to a for loop

2008-12-01 Thread dippa
basic perl problem which is annoying me, the code is: --- #!/usr/bin/perl -w use strict; my $string; my $subString; my @indexes; print "Enter a string:\n"; chomp($string = ); print "\nEnter substring to search for:\n"; chomp($subString = ); ## This while loop does what i'm after #my $pos = -1;