[perl-python] 20050114 if statement

X

Xah Lee

.. # here's an 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.
.. ------------------------------
.. # here's an example of if statement in perl
..
.. $x=31;
.. if ($x<0) {
.. print 'neg'
.. } elsif ($x==0) {
.. print 'zero'
.. } elsif ($x==1) {
.. print 'one'
.. } else {
.. print 'other'
.. }
..
..
.. ---------------------------
..
.. Note: this post is from the Perl-Python a-day mailing list at
.. http://groups.yahoo.com/group/perl-python/
.. to subscribe, send an email to (e-mail address removed)
.. if you are reading it on a web page, program examples may not run
.. because html conversion often breaks the code.
..
.. Xah
.. (e-mail address removed)
.. http://xahlee.org/PageTwo_dir/more.html
 
R

Reinhold Birkenfeld

Xah said:
. # here's an 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.
. ------------------------------
. # here's an example of if statement in perl
.
. $x=31;
. if ($x<0) {
. print 'neg'
. } elsif ($x==0) {
. print 'zero'
. } elsif ($x==1) {
. print 'one'
. } else {
. print 'other'
. }

Note that Perl's print doesn't append a newline to the printed string.

Reinhold
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top