Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
What is C unconditional jump statements?
C programming language provides unconditional jump statements that allow transferring control from one part of the program to another without evaluating any condition. The four main unconditional jump statements are break, continue, return, and goto.
break Statement
The break statement is used to terminate loops or exit from switch blocks immediately. When executed, control jumps to the statement following the loop or block.
Syntax
break;
Example
The following program demonstrates the break statement in a loop −
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 5; i++) {
printf("%d ", i);
if (i == 3)
break;
}
printf("\nLoop terminated<br>");
return 0;
}
1 2 3 Loop terminated
continue Statement
The continue statement skips the remaining statements in the current iteration and jumps to the next iteration of the loop.
Syntax
continue;
Example
The following program demonstrates the continue statement −
#include <stdio.h>
int main() {
int i;
for (i = 1; i <= 5; i++) {
if (i == 3)
continue;
printf("%d ", i);
}
printf("\nLoop completed<br>");
return 0;
}
1 2 4 5 Loop completed
return Statement
The return statement terminates function execution and optionally returns a value to the calling function.
Syntax
return [expression];
Example
The following program demonstrates the return statement −
#include <stdio.h>
int multiply(int a, int b) {
int result = a * b;
return result;
}
int main() {
int x = 5, y = 3;
int product = multiply(x, y);
printf("Product: %d<br>", product);
return 0;
}
Product: 15
goto Statement
The goto statement transfers control unconditionally to a labeled statement within the same function.
Syntax
goto label; label: statement;
Example
The following program demonstrates the goto statement −
#include <stdio.h>
int main() {
printf("Hello ");
goto end;
printf("World ");
end:
printf("TutorialsPoint<br>");
return 0;
}
Hello TutorialsPoint
Key Points
- break exits loops and switch statements completely
- continue skips to the next iteration of a loop
- return exits functions and optionally returns values
- goto should be used sparingly as it can make code harder to understand
Conclusion
Unconditional jump statements provide powerful control flow mechanisms in C. While break, continue, and return are commonly used, goto should be avoided in structured programming for better code maintainability.
