Skip to content

Commit 50c6995

Browse files
Added loops (#49)
* Added operators & moved all type to a new markdown file * Fixed formatting * Added conditions * added Switch markdown file. * added loops Co-authored-by: Beast <jbampton+github@gmail.com>
1 parent 863bd91 commit 50c6995

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

en/_sidebar.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- [Operators](en/operators)
1010
- [Conditions](en/conditions)
1111
- [Switch](en/switch)
12+
- [While Loop](en/while-loop)
13+
- [For Loop](en/for-loop)
1214
- [Installing](en/installing)
1315

1416
- **Contributing**

en/for-loop.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# For Loop
2+
3+
A for loop is a control flow statement for specifying iteration, which allows code to be executed repeatedly. A for loop has two parts: a header specifying the iteration, and a body which is executed once per iteration. The header often declares an explicit loop counter or loop variable, which allows the body to know which iteration is being executed. For loops are typically used when the number of iterations is known before entering the loop. For loops can be thought of as shorthands for while loops which increment and test a loop variable.
4+
5+
## Syntax
6+
7+
```
8+
for (statement 1; statement 2; statement 3) {
9+
// code block to be executed
10+
}
11+
```
12+
13+
- Statement 1 is executed (one time) before the execution of the code block.
14+
- Statement 2 defines the condition for executing the code block.
15+
- Statement 3 is executed (every time) after the code block has been executed.
16+
17+
## Example
18+
19+
```
20+
for (int i = 0; i < 5; i++) {
21+
cout << i << "\n";
22+
}
23+
```
24+
25+
| :point_up: | The example above will print the numbers 0 to 4. |
26+
| ---------- | :----------------------------------------------- |
27+
28+
**Example explained:**
29+
30+
- Statement 1 sets a variable before the loop starts (int i = 0).
31+
32+
- Statement 2 defines the condition for the loop to run (i must be less than 5). If the condition is true, the loop will start over again, if it is false, the loop will end.
33+
34+
- Statement 3 increases a value (i++) each time the code block in the loop has been executed.

en/switch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The expression is evaluated once and compared with the values of each case label
3434
| ------ | :---------------------------------------------------------------------------- |
3535

3636
| :point_up: | By the way, the default clause inside the switch statement is optional. |
37-
| ------ | :---------------------------------------------------------------------- |
37+
| ---------- | :---------------------------------------------------------------------- |
3838

3939
## Example
4040

en/while-loop.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# While Loop
2+
3+
A while loop in One programming repeatedly executes a target statement as long as a given condition is true.
4+
5+
## Syntax
6+
7+
```
8+
while (condition) {
9+
// code block to be executed
10+
}
11+
```
12+
13+
## Example
14+
15+
```
16+
int i = 0;
17+
while (i < 5) {
18+
cout << i << "\n";
19+
i++;
20+
}
21+
```
22+
23+
| :point_up: | In the example above, the code in the loop will run, over and over again, as long as a variable (i) is less than 5. |
24+
| ---------- | :------------------------------------------------------------------------------------------------------------------ |

0 commit comments

Comments
 (0)