Example of Loops and Jump Statements
C
// C program to illustrate loops #include <stdio.h> // Driver code int main() { int i = 0; // for loop with continue for (i = 1; i <= 10; i++) { if (i == 5 || i == 7) { continue ; } printf ( "%d " , i); } printf ( "\n" ); // while loop with break i = 1; while (i <= 10) { if (i == 7) { break ; } printf ( "%d " , i++); } printf ( "\n" ); // do_while loop i = 1; do { printf ( "%d " , i++); } while (i <= 10); printf ( "\n" ); // goto statement i = 1; any_label: printf ( "%d " , i++); if (i <= 10) { goto any_label; } return 0; } |
Output
1 2 3 4 6 8 9 10 1 2 3 4 5 6 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
C Cheat Sheet
This C Cheat Sheet provides an overview of both basic and advanced concepts of the C language. Whether you’re a beginner or an experienced programmer, this cheat sheet will help you revise and quickly go through the core principles of the C language.
In this Cheat Sheet, we will delve into the basics of the C language, exploring its fundamental concepts that lay the groundwork for programming. We will cover topics such as variables, data types, and operators, providing you with a solid understanding of the building blocks of C programming.
Contact Us