0
What is the use of break in python and how it works?
## Counting vowels ## vowels = ["a", "e", "i", "o", "u"] word = input("Enter word : ") count = 0 word_lower = word.lower() for letter in word_lower: if letter in vowels: count = count + 1 break print(count) When i use break in the loop why it doesn't produce expected output and what is its function and how it affects the loop. In which conditions do we use break in program. Please help me through
1 Respuesta
0
It's because in this case the break statement isn't necessary.
When a loop reaches a break statement, it will immediately break out of the loop, so in this case, it only looks at the first letter. I think you confused it with "continue", which skips the current iteration, but even that wouldn't be necessary