[perl-python] 20050114 if statement

Discussion in 'Python' started by Xah Lee, Jan 15, 2005.

  1. Xah Lee

    Xah Lee Guest

    .. # 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
    .. if you are reading it on a web page, program examples may not run
    .. because html conversion often breaks the code.
    ..
    .. Xah
    ..
    .. http://xahlee.org/PageTwo_dir/more.html
    Xah Lee, Jan 15, 2005
    #1
    1. Advertising

  2. 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
    Reinhold Birkenfeld, Jan 15, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    782
  2. Jay McGavren
    Replies:
    11
    Views:
    1,096
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,049
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    442
    Duncan Booth
    Jul 22, 2004
  5. Xah Lee

    [perl-python] 20050114 if statement

    Xah Lee, Jan 15, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    71
    Xah Lee
    Jan 15, 2005
Loading...

Share This Page