Ask coding questions

← Back to all posts
One Line While Loop
Dunce (45)

How would I make a one line while loop?
I know you can do

while True: print("Hello world!")

but then if I put anything before it, like

print("Start!"); while True: print("Hello world!")

I get a syntax error.

novaflippers (55)

Send the code that you want in a 1 liner while loop.

Dunce (45)

@novaflippers print("Hello world!") is good just for an example.

novaflippers (55)

@Dunce That is already a one liner. Im talking about the whole code you want in one line.

Dunce (45)

@novaflippers Is there something I can refer to, to learn how to make one liner while loops?

novaflippers (55)

@Dunce Look it up, something should show. I am a master at python, but I dont understand why would you need 1 liner code anyways

Dunce (45)

@novaflippers I've tried looking it up. How about just two print statements.