diff options
| author | mo khan <mo.khan@gmail.com> | 2020-07-15 11:06:05 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-07-15 11:06:05 -0600 |
| commit | 67bc0208e95a61c92977031cd873c6e5ecf71b9e (patch) | |
| tree | 3db27de33c7b958ed4f02166d1bc225182a487bc | |
| parent | cad5f5a17e1705c1654c51a7034950f794e2495c (diff) | |
Episode 2: Loops and Arrays
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 45 | ||||
| -rw-r--r-- | main.c | 30 |
3 files changed, 71 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b883f1f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.exe @@ -47,3 +47,48 @@ Datatypes * numbers (int, float) * char -> character [A-Za-z] * array -> deck of (similar stuff card, number, char) + + +* Loop + +* 1 -> 2 +* chore weekly basis: + +wash: +1. collect the dirty clothes +2. separate the whites from the colours +3. load the colours into the washing machine +4. add detergent to the washing machine. +5. close the washing machine door/lid +6. start the washing machine + +wash clothes week + +* week 1: wash +* week 2: wash +* week 3: wash +* week .: wash +* week .: wash +* week .: wash +* week n: wash + +rinse and repeat + +* `for` loop +* `while` loop + +* condition: passing the lie detector test +* (1 == 1) -> true +* (0 == 1) -> false + +```c + for (int i = 0; i < 1000000; i = i + 1) { + printf("%d\n", i); + } +``` + +```c + while (1 == 1) { + printf("true\n"); + } +``` @@ -1,14 +1,34 @@ #include <stdio.h> +#include <string.h> int main(int argc, char *argv[]) { - char name[3]; + char bike_rack[8]; + for (int i = 0; i < 8; i = i + 1) + { + bike_rack[i] = '\0'; // NULL -> nothing + } - name[0] = 'm'; - name[1] = 'o'; - name[2] = '\0'; + // rack: [0, 1, 2, 3] + // mo: 'm' + // om: 'o' + // bo: 'b' + // yo: 'y' - printf("%s", name); + bike_rack[0] = 'm'; + /*bike_rack[1] = 'o';*/ + /*bike_rack[2] = 'b';*/ + bike_rack[3] = 'y'; + for (int i = 0; i < 8; i = i + 1) + { + int bike = bike_rack[i]; + printf("bike rack slot %d: %c\n", i, bike); + } + + printf("\n"); return 0; } + +// 1. compile: c -> machine +// 2. run: machine -> os |
