📖 generic · 12th TN - English Medium · COMPUTER SCIENCE · Page 73question

CONTROL STRUCTURES · Part 9

Chapter 2: 3 · COMPUTER SCIENCE

as string. Each letter of the given string sequence is tested till the letter ‘e’ is encountered, when it is encountered the control is transferred outside the loop block or it terminates. As shown in the output, it is displayed till the letter ‘e’ is checked after which the loop gets terminated. One has to note an important point here is that ‘if a loop is left by break, the else part is not executed’.

To explain this lets us enhance the previous program with an ‘else’ part and see what output will be: for word in “Jump Statement”: if word = = “e”: break print (word, end=' ') else: print (“End of the loop”) print (“\n End of the program”) Output: Jump Stat End of the program Example . : Program to illustrate the use of break statement inside for loop Note that the break statement has even skipped the ‘else’ part of the loop and has transferred the control to the next line following the loop block. (ii) continue statement Continue statement unlike the break statement is used to skip the remaining part of a loop and start with next iteration. Syntax: continue 12th Computer Chapter - - Control Structures Test Expression of loop continue?

no Enter loop false true yes Exit loop Remaining body of loop Fig . Working of continue statement The working of continue statement in for and while loop is shown below. for var in sequence: # code inside for loop if condition: continue #code inside for loop #code outside for loop while test expression: #code inside while loop if condition: continue #code inside while loop #code outside while loop for word in “Jump Statement”: if word = = “e”: continue print (word, end = ' ') print (“\n End of the program”) Output: Jump Statmnt End of the program Example . : Program to illustrate the use of continue statement inside for loop 12th Computer Chapter - - The above program is same as the program we had written for ‘break’ statement except that we have replaced

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →