- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements