
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Loops in C and C++
In this tutorial, we will be discussing a program to understand loops in C and C++.
Looping in programming is used when we have to execute a given block code again and again. It takes in the approach for writing the same code line again and again and promoted DRY code practice.
Example
For loop
#include <iostream> using namespace std; int main(){ for (int i = 1; i <= 10; i++){ cout << "Hello World\n"; } return 0; }
Output
Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World
While loop
#include <iostream> using namespace std; int main(){ int i = 1; while (i < 6){ cout << "Hello World\n"; i++; } return 0; }
Output
Hello World Hello World Hello World Hello World Hello World
- Related Articles
- What types of loops are supported in C#?
- What do you mean by odd loops in C language?
- Write a C program to work on statements using functions and loops
- For and While loops in Arduino
- Loops in Java
- For Loops in Javascript
- Loops in Dart Programming
- Array flattening using loops and recursion in JavaScript
- Loops and Control Statements (continue, break and pass) in Python
- How to use multiple for and while loops together in Python?
- How to use nested loops in Python?
- Finding closed loops in a number - JavaScript
- Java Nested Loops with Examples
- What is the difference between for...in and for...of loops in JavaScript?
- Demonstrate nested loops with return statements in JavaScript?

Advertisements