0

For Loop

https://code.sololearn.com/cClC2UWK9qUY/?ref=app When I run the code I expected this result: 1. Dog 2. Cat 3. Hamster But instead is just 1. 1. 1. Can someone tell me whats wrong with the code?

3rd Sep 2022, 6:22 PM
Andres Villarreal
Andres Villarreal - avatar
2 Answers
+ 1
You have a variable inside the loop and with each new run through the loop it is redefined by 1 again
3rd Sep 2022, 6:31 PM
Š•Š²Š³ŠµŠ½ŠøŠ¹ ŠœŠ¾Š»Š“Š¾Š²Š°Š½Š¾Š²
Š•Š²Š³ŠµŠ½ŠøŠ¹ ŠœŠ¾Š»Š“Š¾Š²Š°Š½Š¾Š² - avatar
+ 1
x must be outside the for loop
3rd Sep 2022, 6:31 PM
Š•Š²Š³ŠµŠ½ŠøŠ¹ ŠœŠ¾Š»Š“Š¾Š²Š°Š½Š¾Š²
Š•Š²Š³ŠµŠ½ŠøŠ¹ ŠœŠ¾Š»Š“Š¾Š²Š°Š½Š¾Š² - avatar