Skip to content
Permalink
Browse files
Update.
  • Loading branch information
nagrat committed Mar 15, 2023
1 parent 5239d32 commit 2bfcae8bc57f0c4b2b6cec0691a9197ce5febcd8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
Empty file.
@@ -0,0 +1,32 @@
#include <iostream>

#ifdef _WIN32 // if os is windows
#include "Windows.h" // include Windows.h for sleep method
#endif // end the if

#ifdef linux // if os is linux
#include "unistd.h" // include unistd.h for sleep method
#endif // end the if

#define sleep_time 100 // define macro to sleep for 500 milliseconds (1/2 a second)

using namespace std;

/*
For loops. Iteration over a certain amount of times / elements.
They are used for a lot of shit, can be used for bad stuff too.
*/

void for_loop(int max) {
for (int x = 1; x <= max; x++) { // defining new int called x. stop when x is less than or equal to int max. increment x by 1
cout << x << " "; // print out each number with a space "1 2 3 etc"
Sleep(sleep_time); // making use of a define variable at line 11
}
cout << "\n"; // new line if you don't want the next lines of code on same line
}

int main() {
for_loop(10); // calling the for loop and setting the max to be 10 in this example
for_loop(100); // calling the for loop and setting the max to now being 100!
return 0;
}
@@ -0,0 +1,22 @@
#include <iostream>

using namespace std;

/*
While loops. Can also be known as a forever loop.
Breaks only when a condition is met; usually a boolean.
*/

void while_loop(int max) {
int y = 0;
while (y < max) {
cout << y << " ";
y++;
}
}

int main() {
while_loop(10);

return 0;
}
@@ -9,9 +9,16 @@ This is just how I have files and the [Makefile](makefile_tutorial.md) because I
- Variables
- [Variables](Variables/variables.cpp)
- [Macros](Variables/macros.cpp)
- [Macros2](Variables/macros2.cpp)
- [Pointers](Variables/pointers.cpp)
- [Shared Pointers](Variables/shared_pointers.cpp)
- [Smart Pointers](Variables/smart_pointers.cpp)
- [Vectors](Variables/vectors.cpp)
- [Arrays](Variables/arrays.cpp)
- Loops
- [For](Loops/for.cpp)
- [While](Loops/while.cpp)
- [Do While](Loops/do_while.cpp)
- Functions
- [Functions](Functions/functions.cpp)
- [Templates](Functions/templates.cpp)

0 comments on commit 2bfcae8

Please sign in to comment.