C - Jumping Statements

 Jumping Statements:

1.   break

2.   continue

3.   goto

4.   exit

 1. break:-

The break statement provides an early exit from for, while, and do, just as from switch. A break causes the innermost enclosing loop or switch to be exited immediately.

SYNTAX-

break;

EXAMPLE-

/* Example of break */

main()

{

int a;

for (a=1;a<6;a++)

{

If (a==4)

{

break;

}

printf (“%d”,a);

}

}

Output-

1

2

3

 2. continue:-

The continue statement is used to bypass the remainder of the current pass through a loop. That is, it passes the flow of control to the next iteration within for, while or do loops.

In the while and do, this means that the test part is executed immediately; in the for, control passes to the increment step. The continue statement applies only to loops, not to switch.

SYNTAX- continue;

EXAMPLE-

/* Example of continue */

main()

{

int a;

for (a=1;a<6;a++)

{

If (a==4)

continue;

printf (“%d”,a);

}

}

Output-

1

2

3

5

 3. goto:- It is use to go from one part to another part of a program.

SYNTAX-

goto label name;

EXAMPLE-

/* Example of goto */

main()

{

int a=1;

one:

printf(“%d\n”,a);

a++;

if (a<=4)

{

goto one;

}

}

Output-

1

2

3

4

 4. exit:- It is use to exit from any program.

SYNTAX-

exit();

EXAMPLE-

/* Example of exit */

main()

{

int a;

for (a=1;a<=6;a++)

{

if (a==4)

exit();

printf(“Bye”);

}

}

Output-

Bye

Bye

Bye

Comments

Popular posts from this blog

Courses After 12th Science

MS Office Versions List

Computer - Network Topologies