Example 5: if...else

Overview

In this example, you will learn how to use conditional statements

Example Code

Output

Sequence One and Sequence Two are equal!

 

Decode

>> Line 19-32 : If...else

if (some condition is true)
{
do something
}

elsif(some other conditon is true)
{
do some other thing
}

else
{
do something else

}

To compare if two variables are the same, use == (equal)

if ($sequenceOne == $sequenceTwo)
{
print "Same Sequence";
}

To compare if two variables are different, use != (not equal)

if ($sequenceOne != $sequenceTwo)
{
print "Different Sequence";
}

Other comparison operators

>= (greater than or equal)

<= (less than or equal)

Exercise Five

>> Write a program that finds the total number of Gs and Cs and use conditional statement to find out which number is the greater. Print your results.

$sequence="GCACAGGGTGAACGTAACGATGGCTGATCGTATAAGTGTGACTATGGCCGACACTGATAGAGT

CAACTTGACCATGCACAGGGTGAACGTAACG ";