We have seen the break statement in relation to the switch-case statements. Similarly we can use break statements in the while and for loops to exit the loop before the predetermined condition. It can be used to handle error or any exceptional condition.
The above program skeleton shows the use of break. ‘ ’ character entered as input is the terminating condition for inner while loop. But if character entered is ‘*’, break statement causes exit from the while loop.
Break causes exit only from the loop in which it is used. i. e. in our program though while is nested in for, break, exit only while loop, causing execution to resume from statement following while.
There is another statement known as continue statement, which is used to skip remainder of current run through the loop and continue execution of loop from the beginning with the next value of index.
The above example illustrates use of continue statement. j runs from 0 to n. if a is less than 0, then continue statement causes remaining body of for loop to be skipped and execution again begins from for statement i.e. j = 3. i.e. all values in the array, which are negative, are skipped.
C Related Interview Questions
|DBMS Interview Questions||C++ Interview Questions|
|C & Data Structures Interview Questions||Java Interview Questions|
|Go (programming language) Interview Questions||F Sharp (programming language) Interview Questions|
|C preprocessor Interview Questions||R Programming language Interview Questions|
|D Programming Language Interview Questions||Lua (programming language) Interview Questions|
|Embedded C Interview Questions|
Introduction To C-programming
Data Types And Storage Classes
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.