0

I don't understand this loops thing

22nd May 2019, 11:16 AM
Samuel Berlucci
Samuel Berlucci - avatar
10 Respuestas
0
+= -= *= /= %= Are shorthands for x = x + x x = 0; x += 5 means x = x + 5; result: 5 x -= 5 means x = x - 5; result: -5 x *= 5 means x = x * 5; result 0 Etc In your case, x+= 2 means x = x + 2
22nd May 2019, 11:44 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 5
Which part exactly?
22nd May 2019, 11:22 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
while loops repeat the code inside their bodies until their condition fails. Meaning that the thing inside their brackets becomes false. In most languages, 0 evaluates to false and all other numbers to true. Is there any specific sample in the tutorial that confused you perhaps?
22nd May 2019, 11:27 AM
Valen.H. ~
Valen.H. ~ - avatar
0
Everything about the while loops
22nd May 2019, 11:25 AM
Samuel Berlucci
Samuel Berlucci - avatar
0
i = 1 while i <=5: print(i) i = i + 1 print("Finished!") Why does it print 1 2 3 4 5 Finished!
22nd May 2019, 11:32 AM
Samuel Berlucci
Samuel Berlucci - avatar
0
While will repeat the code as long as the condition is true Today is sunny, while its sunny, go outside If it starts raining, get back inside bool weather = sunny; While (sunny) { go outside } You also need a condition so you're not stuck in endless sunny days - it's usually sunny for 5 days sooo int days = 0; while (sunny && days <5 ) { go outside days++ (this will add a new day after the code runs) } On the fourth day, variable "days" will hit 5 and you will go back inside
22nd May 2019, 11:32 AM
HNNX 🐿
HNNX 🐿 - avatar
0
Loop executes 5 times and runs the print command After its done looping, it prints out finish
22nd May 2019, 11:35 AM
HNNX 🐿
HNNX 🐿 - avatar
0
Ok, thanks alot. I understand now. Very easy
22nd May 2019, 11:36 AM
Samuel Berlucci
Samuel Berlucci - avatar
0
Pls can you explain the x+=2
22nd May 2019, 11:39 AM
Samuel Berlucci
Samuel Berlucci - avatar
0
Amazing 😍👌. You too good . thanks again
22nd May 2019, 11:47 AM
Samuel Berlucci
Samuel Berlucci - avatar