HomeMathComputingArtsWordsLiteratureMusictwitter facebook webfeed

Perl & Python: “if” Statement Example

Advertise Here For Profit

Xah Lee, 2005-01-14

Python

# example of if statement in python.

x = -1
if x<0:
     print 'neg'
elif x==0:
     print 'zero'
elif x==1:
     print 'one'
else:
     print 'other'

# the elif can be omitted.

Python Doc

Perl

# example of if statement in perl

$x = -1;
if ($x<0) {
  print 'neg';
} elsif ($x==0) {
  print 'zero';
} elsif ($x==1) {
  print 'one';
} else {
  print 'other';
}

perldoc perlsyn

blog comments powered by Disqus