Hi friends! Till now, I think we have grabbed sufficient to start out
study of flow of control in PERL programming. By flow of control, I mean how
the control of program passes from one step to another. It can be understood as
the main deciding factor or program flow logic.
In our previous blog learning session, I introduced ‘if-else’
statements; however, I left their deep understanding for today. So, let us
understand the functioning of these ‘if-else’ statements today.
The ‘if’ statement is used to specify a particular
condition, often, a logic statement. It can be understand by following syntax:
if (<condition>)
{
<Steps to follow>
}
Consider the following code fragment to understand this
syntax:
if ($x==0)
{
print “\nThe value of x is
zero”;
}
The above code fragment is used to check whether the
value of x is zero. To judge this, we first used if statement with condition “$x==0”,
which means the statement that “x equals zero”. If this condition is found
true, the statement body will be executed, which prints “The value of x is
zero.” on the screen, otherwise, it will be skipped.
If it is needed that provided the first condition is
skipped, the program will check for the second condition, ‘if-else’ or ‘else’
statement is used. The general syntax of ‘if-else’ nesting, which can be extend
to the limit we need, is:
if (<condition_1>)
{
<Steps to follow>
}
else if (<condition_2>)
{
<Steps to follow,
provided condition_1 is wrong>
}
else
{
<Steps to follow,
provided all conditions are wrong>
}
We will understand the ‘if-else’ nesting with a suitable
example in our tomorrow’s learning session on this blog.
Hope you enjoyed today’s learning session on PERL.
Happy Republic Day to my readers from India.
As always, if you find anything difficult or if you have
any suggestion, please feel free in discussing with me.
With Warm Regards,
Yajur Kumar
(PERL Programming Expert)
Yajur Kumar
(PERL Programming Expert)
Thanks for share useful tips for perl
ReplyDeleteWebsite Design in Bangalore