May i ask how i can use while true / while loop to write the code.
i = "APPLE"
while True:
if i == "APPLE":
print(i)
i get Syntax Error form above code.
i = "APPLE"
while True:
if i == "APPLE":
print(i)
i get Syntax Error form above code.
How to use while true/while loop on python
|
May i ask how i can use while true / while loop to write the code.
i = "APPLE" while True: if i == "APPLE": print(i) i get Syntax Error form above code.
1. From what I see, there are no indentations
2. There is a space between "print" and the parenthesis calling the function 3. I don't know if this is what you want, but it will continue to print even after i == 'apple' Here's a better way to do this while i != 'apple': #Will continue to loop until i is equal to "apple" pass #pass so there are no syntax errors print(i) #When the while loop finishes, print will be executedYou could also use a break (Though I think the first example of code is better) while True: if i == apple: print(i) break #Break out of the while loop
Oct-07-2019, 01:45 PM
What do you want to accomplish?
This code will endlessly print APPLE: i = 'APPLE' while True: if i == 'APPLE' print(i) # Ctrl + C to cancelPython has built-in help, type help('while') into your interactive interpreter and you will have official documentation at your disposal (press Q to quit help).
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. (Oct-07-2019, 01:45 PM)perfringo Wrote: What do you want to accomplish? if system output send me "APPLE" i will get APPLE else system will reply "error data"
Oct-08-2019, 08:02 AM
(Oct-08-2019, 01:25 AM)christing Wrote: if system output send me "APPLE" i will get APPLE else system will reply "error data" To remove ambiguity please define 'system output', 'I will get' and 'system reply'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
While True loop help | Nickd12 | 2 | 2,007 |
Oct-17-2020, 08:12 AM Last Post: Nickd12 |
|
Is using while True loop good? | escape_freedom13 | 5 | 3,591 |
Jul-03-2020, 08:27 PM Last Post: escape_freedom13 |
|
Do break operators turn while loop conditions from True to False? | Drone4four | 5 | 3,017 |
Oct-24-2019, 07:11 PM Last Post: newbieAuggie2019 |
|
Returning True or False vs. True or None | trevorkavanaugh | 6 | 9,315 |
Apr-04-2019, 08:42 AM Last Post: DeaD_EyE |
|
file.write stops while true loop from executing in python3 | boonr | 3 | 3,140 |
Mar-25-2019, 12:50 PM Last Post: ichabod801 |
|
How to make loop go back to the beginning if test evaluaes to True. | FWendeburg | 1 | 2,853 |
Feb-13-2019, 01:26 AM Last Post: stullis |
|
Returning true or false in a for loop | bbop1232012 | 3 | 8,203 |
Nov-22-2018, 04:44 PM Last Post: bbop1232012 |
|
Get True of false outside a loop | morgandebray | 2 | 2,478 |
Aug-09-2018, 12:39 PM Last Post: morgandebray |