I don't understand how using i makes an input a loop, or what i even means. help pls | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

I don't understand how using i makes an input a loop, or what i even means. help pls

9th Aug 2016, 4:16 AM
Ben
4 Respostas
+ 1
i doesn't make a loop. let's start with a couple of basics on loops (informal explanation): 1. loops allow the same instructions (code) to run over and over, usually until a condition is met which stops the loop. 2. your primary loops as a beginner are going to be "while" and "for" 2a. while loop - a while loop runs the code within it until something explicitly tells it to stop. basic example: #ask the user for the secret password string guess = str(input("Enter your password: ")) #create a loop that will allow user to guess #the password until letmein is entered while guess != "letmein": guess = str(input("Please try again: ")) #if isn't letmein, ask again #now out of loop, letmein was entered #congratulate user print("Good job! Password accepted!") 2b. for loops iterate over data / conditions example: #control variable is initiated in the loop #it doesn't have to be i, can be anything #i is just convention for i in range(0, 3): #let's tell the user current value of i print i the output would be: 0 1 2 all of this to say, i doesn't create loops. if you see it as part of a loop, that's just general convention to use the letter i hope this helps some
9th Aug 2016, 4:54 AM
Izz
Izz - avatar
+ 1
thank you so much it helps a lot! I appreciate your help very much. I understand now.
9th Aug 2016, 7:12 AM
Ben
+ 1
glad I could help
9th Aug 2016, 7:12 AM
Izz
Izz - avatar
+ 1
wow fantastic answer thank you lzz!!!
9th Aug 2016, 4:13 PM
ā€Žā€ā€Žā€ā€ŽJoe
ā€Žā€ā€Žā€ā€ŽJoe - avatar