hits counter
  Create Free Blog | Random Blog »   Report Abuse | Login   

 

Archive for the 'Jump statements' Category

Return statement

A return statement is used to transfer the control back to the caller of the method.Used to return a value to the calling method.A return statement immediately terminates the method in which it is executed.
Syntax:
return(value);
Example :
int MAX(int x,int y)
{
if (x>y) return x;
return y;
}

Continue

In ‘while’ and ‘do-while’ loops a ‘continue’ statement transfer the control directly to the conditional expression.But in ‘for’ loop control first go to the iteration part and then go to the conditional expression.
Example:
for (int i=0; i<20; i++)
{
cout<<”i:”<<i<<endl;
if ((i%2)==0) continue;
cout <<endl;
}

Break

The break statement has three uses

Terminates a statement sequence in a statement.
It can be used to exist from a loop.
It can be used as a civilized form of ‘goto’ statement.

Example:
1. for (int i=0; i<20; i++)
{
if (i==10) break;
cout <<”value of i is: “<<i;
}
2.int n=0;
while (n<20)
{
if (n==10) break;
cout<<”value of n is:”<<n++;
}