Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 30th, 2004, 10:29 PM
perfect20002 perfect20002 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 28 perfect20002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
newbie having trouble - defining

how do I define 'while true' in this program.


Code:
count = 0
while true:
      count += 1
      if count > 10:
          break
      if count == 5:
           continue
      print count
      raw_input('press the enter key to exit')

# this program is suppose to count from 1 to 10 and skip 5

Last edited by netytan : April 30th, 2004 at 11:41 PM.

Reply With Quote
  #2  
Old April 30th, 2004, 11:30 PM
NetBSD NetBSD is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: Canada
Posts: 234 NetBSD Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 9 h 25 m 35 sec
Reputation Power: 0
Send a message via MSN to NetBSD
The while statement will loop as long as the expression next to it is true. Using the word "True" is like using while 1:, or in other words, it will loop forever. You don't need to define the "True" constant, because it is built into Python, so just use "True".

To answer the question in your other thread: The variable "count" is used to count the amount of interations, and once it passes 10, the loop exits.

This information is all avaible on Python's website, so please have a look: Python.org

Last edited by NetBSD : April 30th, 2004 at 11:35 PM.

Reply With Quote
  #3  
Old April 30th, 2004, 11:46 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
A better way to do this would be to use a while expression instead of True i.e.

Code:
count = 1
while count <= 10:
    if count != 5:
        print count
    count = count + 1
raw_input('press the enter key to exit')


you can also use a for loop for this simple task.

Code:
for number in range(1, 10): if number != 5: print number


In this instance using a while True loop is a waste of time but its up to you.

Hope this helps

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #4  
Old May 3rd, 2004, 09:12 PM
perfect20002 perfect20002 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 28 perfect20002 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks netytan you've been a great help, your code worked.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > newbie having trouble - defining


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT