Browse Source

Updated TOC

master
Chase Hall 1 month ago
parent
commit
7cdf28194e
1 changed files with 86 additions and 1 deletions
  1. +86
    -1
      Notes/2020_09_21/Notes.md

+ 86
- 1
Notes/2020_09_21/Notes.md View File

@ -1 +1,86 @@
#
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**
- [Loops](#loops)
- [While Loop](#while-loop)
- [Terminology](#terminology)
- [Do-While Loop](#do-while-loop)
- [For Loop](#for-loop)
- [Common Loop Uses](#common-loop-uses)
- [Loops can be nested](#loops-can-be-nested)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
# Loops
## While Loop
```
int i =1;
while (i<=10){
printf("%d\n", i);
i=i+1;
}
```
* While I is less than 10, print the number, then add one to it.
---
## Terminology
* Loop Counter -> `int i = 1;` (Keep track of where in the loop we are)
* Condition -> `while (i<=10){`
* Loop Body -> `// things inside the loop`
---
## Do-While Loop
```
int i=1;
do{
printf("%d\n", i);
i++;
} while (i<=10);
```
---
## For Loop
```
int i;
for (i=1//initialization; i<=10//condition; i++//increment){
// We have a variable I, i=1 only happens ONCE when the loop starts, then we check our condition, so we do the body of our loop, then the third thing happens at the end of the for loop
}
```
---
## Common Loop Uses
* for
* A loop that runs exactly N times
* while
* A loop that runs until some condition is reached
* might run 0 times
* do-while
* a loop that runs until some condition is reached
* guaranteed to run at least once
---
## Loops can be nested
```
int i, j;
for (i=0; i<10; i++){
for(j=0; j<10; j++){
printf("NA");
}
}
printf(" BATMAN!\n");
```

Loading…
Cancel
Save