Use break to stop execution and break out of the current loop : break « Statement « Python Tutorial






# Use continue to stop execution of the current iteration and start the next iteration of the current loop


word = "this is a test"
string = ""
for ch in word:
    if ch == 'i':
        string +='y'
        continue
    if ch == ' ':
        break
    string += ch
print string








3.5.break
3.5.1.Breaking Out of Loops
3.5.2.break out of a while loop
3.5.3.Use break to stop execution and break out of the current loop
3.5.4.break and continue Statements, and Else Clauses on Loops