Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   [perl-python] 20050114 if statement (http://www.velocityreviews.com/forums/t340335-perl-python-20050114-if-statement.html)

Xah Lee 01-15-2005 03:34 AM

[perl-python] 20050114 if statement
 
.. # 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 perl-python-subscribe@yahoogroups.com
.. if you are reading it on a web page, program examples may not run
.. because html conversion often breaks the code.
..
.. Xah
.. xah@xahlee.org
.. http://xahlee.org/PageTwo_dir/more.html


Reinhold Birkenfeld 01-15-2005 07:39 AM

Re: [perl-python] 20050114 if statement
 
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


All times are GMT. The time now is 06:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.