A basic question about while true

0 votes

level: beginner

def play_game(word_list):

hand = deal_hand(HAND_SIZE)# random init

while True:

cmd = raw_input('Enter n to deal a new hand, r to replay the last hand, or e to end game: ')

if cmd == 'n':

hand = deal_hand(HAND_SIZE)

play_hand(hand.copy(), word_list)

print elif cmd == 'r':

play_hand(hand.copy(), word_list)

print elif cmd == 'e':

break else:

print "Invalid command."

my question: while WHAT is True?

i reckon saying 'while true' is shorthand but for what? while the variable 'hand' is being assigned a value? and what if the variable 'hand' is not being assigned a value?

Aug 8, 2018 in Python by Priyaj
• 58,090 points
492 views

1 answer to this question.

0 votes

while True means loop forever. The while statement takes an expression and executes the loop body while the expression evaluates to (boolean) "true". True always evaluates to boolean "true" and thus executes the loop body indefinitely. It's an idiom that you'll just get used to eventually! Most languages you're likely to encounter have equivalent idioms.

Note that most languages usually have some mechanism for breaking out of the loop early. In the case of Python it's the break statement in the cmd == 'e' case of the sample in your question.

answered Aug 8, 2018 by bug_seeker
• 15,520 points

Related Questions In Python

0 votes
1 answer

a basic question about “while true”

while True means loop forever. The while ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,450 points
5,406 views
0 votes
1 answer

.What is the meaning of "while True :" while doing in a loop.

The body of the loop will continue ...READ MORE

answered Oct 7, 2020 in Python by Gitika
• 65,910 points
439 views
0 votes
1 answer

Return a list inside a for loop while iterating over the elements of another list

The print() is getting called multiple times ...READ MORE

answered Sep 22, 2018 in Python by SDeb
• 13,300 points
4,682 views
0 votes
1 answer

Question on PyQt: How to connect a signal to a slot to start a background operation in Python

It shouldn't matter whether the connection is ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,560 points
1,541 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,069 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,490 views
+2 votes
4 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,520 points
119,748 views
0 votes
5 answers

how to exit a python script in an if statement

Instead of using the normal UTF-8 encoding, ...READ MORE

answered Jul 4, 2023 in Python by bodymist
• 140 points
349,496 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP