By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

[perl-python] 20050114 if statement

P: n/a
.. # 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 pe*******************@yahoogroups.com
.. if you are reading it on a web page, program examples may not run
.. because html conversion often breaks the code.
..
.. Xah
.. xa*@xahlee.org
.. http://xahlee.org/PageTwo_dir/more.html

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Xah Lee wrote:
. # 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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.