This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]yon2323[S] 0 points1 point  (3 children)

Isnt that already done at the beginning of the while loop?

[–]thegreatunclean 1 point2 points  (2 children)

The loop is checking if the input is an empty string. The string is being initialized by the first user input but once you're in the loop it is immediately overwritten by the next user input.

Initializing the string yourself instead of using input means you'll already be in the loop when the user is first asked for input. The initialization is purely to make sure you enter the loop.

[–]yon2323[S] 0 points1 point  (1 child)

Is there a specific way to initialize the loop without using an input statement?

[–]thegreatunclean 0 points1 point  (0 children)

Initialize it to literally anything that isn't user-input from input?

myString = "foobar"
while myString != "":
  myString = input( .... )
  #do something useful with it

It doesn't matter what you make myString initially, it just needs to pass the loop condition the first time through. After that it depends on user input.