Skip to content

Commit 76c444b

Browse files
authored
Add files via upload
1 parent d219053 commit 76c444b

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Using do while loop where you have to do something atleast once
2+
3+
#include<iostream>
4+
using namespace std;
5+
6+
int main()
7+
{
8+
int i = 10;
9+
do
10+
{
11+
cout<<"Prints once although i is 10\n";
12+
} while (i<10);
13+
14+
}

Part 2 - Loops/Loops - for.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int fact = 7;
7+
int factorial = 7;
8+
for(int i = fact-1;i>=1;i--)
9+
{
10+
factorial *= i;
11+
}
12+
cout<<factorial<<endl;
13+
}

Part 2 - Loops/Loops - while.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int fact = 8;
7+
int i = fact - 1;
8+
while(i>0)
9+
{
10+
fact *= i;
11+
i--;
12+
}
13+
cout<<fact<<endl;
14+
return 0;
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include<iostream>
2+
//#include<vector>
3+
#include<bits/stdc++.h>
4+
using namespace std;
5+
// Compile using c++11 --> 'g++ Range_Based_Loops.cpp -std=c++11'
6+
int main()
7+
{
8+
vector<int> data = {1,2,3,4,5,6};
9+
// Can be used for arrays/ STL arrays.
10+
// When C array passed to a function it is passed via reference and it looses track of its size
11+
// Thus this doesnt implicitly work in that case..Figure a way out in such case.
12+
for(int n:data)
13+
{
14+
// n stores data temporarily from data
15+
cout<<n<<"\t";
16+
}
17+
cout<<endl;
18+
/*
19+
for(int i =0;i<6;i++)
20+
{
21+
cout<<data[i]<<"\t";
22+
}
23+
cout<<endl;
24+
*/
25+
}

0 commit comments

Comments
 (0)