Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 14th, 2005, 12:24 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
SOLVED: Newbie question.

I've programmed a third of an engine for an RPG but I don't know what while does... :eek:

I see sometimes just

while a:

or

while 1:

I know that adding a condition afterwards loops the indentation lines until that condition becomes untrue. But what if there is no condition like the two I mentioned above?

Last edited by Sane; Apr 14th, 2005 at 2:47 PM.
Sane is offline   Reply With Quote
Old Apr 14th, 2005, 2:04 PM   #2
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
I am not sure what you are asking here.
while 1:
    print "Stuck in an infinite loop"
The code above is called an infinite loop. The condition will always evaluate to true and the only way to stop the program is kill it (Control-C).

You would usually use it with a break statement. For example:
while 1:
    s = raw_input("Type yes to end: ")
    if s == "yes":
        break
    else
        print "Not ending!"

Last edited by Moldz; Apr 14th, 2005 at 2:14 PM.
Moldz is offline   Reply With Quote
Old Apr 14th, 2005, 2:25 PM   #3
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,827
Rep Power: 5 Sane will become famous soon enough
Gah. I'm used to these just being called

"loop:"

Stupid new terms...>_<

Then why have I seen while a? o_O

Well thanks.
Sane is offline   Reply With Quote
Old Apr 14th, 2005, 3:20 PM   #4
Moldz
Programmer
 
Moldz's Avatar
 
Join Date: Feb 2005
Posts: 54
Rep Power: 4 Moldz is on a distinguished road
Because a is a variable.
a = True
b = 0
while a:
  print b
  b += 1
  if b == 3:
    a = False
Moldz is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC