[perl-python] 20050115, for statement

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

  1. Xah Lee

    Xah Lee Guest

    © # this is an example of for statement
    © # the % symbol calculates the remainder
    © # of division.
    © # the range(m,n) function
    © # gives a list from m to n-1.
    ©
    © a = range(1,51)
    © for x in a:
    © if x % 2 == 0:
    © print x, 'even'
    ©
    © # note that in this example, for goes over a list.
    © # each time making x the value of the element.
    ©
    © ------------------------------------
    © # this is similar code in perl
    ©
    © @a=(1..50);
    © for $x (@a) {
    © if ( $x%2 ==0){
    © print $x, " even\n";
    © }}
    ©
    © # PS each daily tip can be run. Just
    © # copy the python part and save to a
    © # file and run it as "python
    © # file.py". Try it.
    ©
    ©
    © 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
    © groups.google.com changes the post slightly.
    ©
    © Xah
    ©
    © http://xahlee.org/PageTwo_dir/more.html
     
    Xah Lee, Jan 15, 2005
    #1
    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:
    817
  2. Jay McGavren
    Replies:
    11
    Views:
    1,159
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,128
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    479
    Duncan Booth
    Jul 22, 2004
  5. Xah Lee
    Replies:
    5
    Views:
    335
    Peter Hansen
    Jan 17, 2005
Loading...

Share This Page