Jump statements

-> Goto [Avoided in normal programming.]

-> Continue

-> Break

-> Return

 

Syntax are as follows:

-Goto:

goto label;
statement1;
label: statement2;

Only statement2 will be executed and statement 1 won’t be executed as the programs makes a jump to label.

 

-Continue:

Example:

for(i=0;i<=n;i++)

{

statement1;

continue;

statement2;

}

 

In this loop statement1 gets executed and statement2 will not be executed!

Continue statement after statement1 takes the control back to the decision making

i.e., foor loop here, and hence it skips the statement2 in each execution till n.

 

-Break:

Eg:

while(condition)

{

printf(“hi”);

break;

printf(“hello”)

}

 

This program prints hi and won’t print hello because before it moves to the

statement which prints hello break is encountered which beings the control out of the while loop and hence only hi is printed.

 

-Return:

return(value)

Eg:

main()

{

return(0)

}

It returns 0 to the main function.

 

 

 

Sentinel loops

In sentinel loops we don’t know that how many no. of times the loop will work!

That means that a sentinel loop can be regarded as infinite, indefinite loop.

For Eg:

main()

{

int x=1;

while (x=1)

{

printf("This is an infinite loop!");

}

}

 

Output will be an infinite loop printing “This is an infinite loop!” infinitely!! 🙂