-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForLoopsBasicDEMO.cpp
More file actions
38 lines (30 loc) · 1.02 KB
/
Copy pathForLoopsBasicDEMO.cpp
File metadata and controls
38 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//************************************************************************
// Author: Rolando Carreon
// Date: feb 25 2025
// Language: C++
// Assignment: ForLoopBasicDEMO
// Description: show counting with a forloop
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
// declare local variables
// for each number from 0 to 10, display the number
// increments the 'i' counter till it reaches 10 // subtract to inc down
// i += 2 // would incrmeent by two instead of one
for(int i = 0; i<= 10; i++)
{
cout << "The counter 'i' is " << i << endl;
}
cout << endl << endl;
// loop through a range of numbers, displaying the even numbers
for(int i = 0; i <= 20; i++)
{
// if the number is even display the number using % 2 == 0
// use % 2 != 0 to count odd numbers instead
if(i % 2 == 0)
cout << "The counter 'i' is " << i << endl;
}
return 0;
}