Unconditional Sequence Control Statements?




Unconditional Sequence Control Statements?

Break − Using break we can leave a loop even if the condition for its end is not fulfilled. It can be used to end an infinite loop, or to force it to end before its natural end. For example, we are going to stop the count down before its natural end.

For Example:

for (n=10; n>0; n--)
{
	cout<<n<<",";
	if(n==3)
	{
		cout<<"countdown aborted!";
		break;
	}
}

Goto − Branches unconditionally from one point tp another point in program. The general form of goto is

goto lable;
statement;
:
:
lable : statement

Goto allows to make an absolute jumb to another point in the program.

The destination point is identified by a label, which is then used as an argument for the goto statement. A label is made of a valid identifier followed by a colon (:).

For Example:

//goto loop example
int main()
{
	int n = 10;
	loop:
	cout<<n<<",";
	n--;
	if(n>0)goto loop;
	cout<<"FIRE!\n";
	return0;
}

Continue − The continue statement causes the program to skip the rest of the loop. in the current iteration as if the end of the statement block had been reached, causing it to jump to the start of the following iteration. For example, we are going to skip the number 5 in our countdown:

For Example:

//continue loop example
int.main()
{
	for(int n = 10; n > 0; n--)
	{
		if(n==5)continue;
		count<<n<<",";
	}
	count<<"FIRE!\n";
	return0;
}