Using if statements with relational and equality operators : If « Statement « Perl






Using if statements with relational and equality operators

   

print "Please enter first integer: ";
$number1 = <STDIN>;
chomp $number1;

print "Please enter second integer: ";
$number2 = <STDIN>;
chomp $number2;

print "The integers satisfy these relationships: \n";

if ( $number1 == $number2 ) {
   print "$number1 is equal to $number2.\n";
}

if ( $number1 != $number2 ) {
   print "$number1 is not equal to $number2.\n";
}

if ( $number1 < $number2 ) {
   print "$number1 is less than $number2.\n";
}

if ( $number1 > $number2 ) {
   print "$number1 is greater than $number2.\n";
}

if ( $number1 <= $number2 ) {
   print "$number1 is less than or equal to $number2.\n";
}

if ( $number1 >= $number2 ) {
   print "$number1 is greater than or equal to $number2.\n";
}

   
    
    
  








Related examples in the same category

1.A program containing a simple example of an if statement.
2.A program that uses the if-else statement.
3.A program that uses the if-elsif-else statement.
4.Conditional Control Statements
5.Conditional Modifiers and print
6.Conditional Modifiers: The if Modifier
7.Extend the if statement to include an else block
8.If and else
9.If start with - no repeat
10.If statement and integer comparsion
11.If statement in a while statement
12.If statement ladder
13.If statement with else
14.If statement with scalar variable
15.Nest if statement into for loop
16.Perl has a number of string comparison operators you can use in if statements.
17.Plural format and ternary operator
18.Plural message
19.Plural output with if statement
20.The if Construct
21.The if/else Construct
22.The if/elsif/else Construct
23.Use an elsif statement to check if a different condition is true
24.Use if statement to check the integer value
25.Using if statement to check if a variable has been defined
26.Using if statement to check if a variable is zero
27.Using if statement to check the number entered from keyboard
28.Using the equality-comparison operator to compare two numbers entered at the keyboard.
29.Using the if elsif statement to check the number entered from keyboard
30.if in a while loop
31.if scope
32.if statement
33.if/else statement
34.if/elsif statement