#!/usr/bin/perl

# filename:  whileloop.pl

# Some looping examples.

# first.....an infinite loop

use strict;
my $name;

while (1<2)           # this is always true
{
	print "Enter your name ";
	$name=;
	chomp($name);
	print "Hello ",name,"\n";
}




# that was REALLY bad. Let's try the same thing BUT.....
# lets exit the loop if the user enters the string "stop"

while (1<2)           # this is always true
{
	print "Enter your name ";
	$name=;
	chomp($name);
	
	if ($name eq "stop")		# if the user typed in "stop", we jump out of the loop
	{
	    last;
	}
	
	print "Hello ",name,"\n";
}
print "That is all\n";


# a loop to add all the numbers from 1 to 100

my $sum;
my $x;

$x=1;
$sum=0;

while($x <=100)
{
	$sum=$sum+$x;
	$x=$x+1;
}
print "The sum is ",$sum,"\n";