#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13

    Using if and for in 1 statemnt


    How can i use both if and for statemtns in one line:

    Code:
    if not somevar for times in range(0, 5):
    why is this worng?
    What is now proved was once only imagined!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    873
    Rep Power
    275
    what programming language is this?
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,280
    Rep Power
    13
    Python of course and the question is how can i use if and for in one statement.

    Comments on this post

    • DonR disagrees : if it were so obvious to be python, why didnt't you post this in the python forum instead of the Linux forum?
    What is now proved was once only imagined!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,446
    Rep Power
    1751
    Never really used Python, but does it not rely upon indents to control things such as when ifs and loops terminate? Sorry, not quite finished my first coffee of day so not being too clear!
    Questions I would have are:
    Why do you actually wish to do this?
    To be clever is not a good enough response, btw!
    Is having a statement on the same line as a conditional valid?
    Code:
      if x = y do this
    or
    Code:
      if x = y
        do this
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    873
    Rep Power
    275
    according to THIS LINK, you can put multiple python statements on single line if you separate each statement with a semi-colon ( ; ).

IMN logo majestic logo threadwatch logo seochat tools logo