diff --git a/CHANGELOG.md b/CHANGELOG.md index 35bc5d6ba8..4069ac094e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -159,6 +159,9 @@ Types of change: - [Python Data Analysis - Creating Your First Notebook - Add missing identifiers](https://github.com/enkidevs/curriculum/pull/2713) - [Python - Calling Functions - Improve readability](https://github.com/enkidevs/curriculum/pull/2705) +### Added +- [Python & Javascript - Glossary - Add glossary on for, while, if and function creation](https://github.com/enkidevs/curriculum/pull/2708) + ## May 12th 2021 ### Fixed diff --git a/glossary/javascript/js-for-loop.md b/glossary/javascript/js-for-loop.md new file mode 100644 index 0000000000..f5b0292cbb --- /dev/null +++ b/glossary/javascript/js-for-loop.md @@ -0,0 +1,12 @@ +# For + +A `for` loop is used when you want to execute a piece of code a specified number of times. + + +```javascript +// Create variable i, set the condition to "as long as i is less than 3", increase i by 1 after every loop cycle +for (let i = 0; i < 3; i++) { + // Code that is executed on every cycle + console.log("The current value of i is", i, "."); +} +``` \ No newline at end of file diff --git a/glossary/javascript/js-function-creation.md b/glossary/javascript/js-function-creation.md new file mode 100644 index 0000000000..600df735a2 --- /dev/null +++ b/glossary/javascript/js-function-creation.md @@ -0,0 +1,14 @@ +# Function + +Functions are pieces of code designed for a particular task. + +Functions are executed by performing a function call. + +```javascript +function addition(x, y) { + return x + y; // Returns the sum of x and y +} + +// Function called with values for x and y +addition(11, 3); +``` \ No newline at end of file diff --git a/glossary/javascript/js-if-else.md b/glossary/javascript/js-if-else.md new file mode 100644 index 0000000000..353303832d --- /dev/null +++ b/glossary/javascript/js-if-else.md @@ -0,0 +1,19 @@ +# If & if-else + +An `if` is a conditional statement that executes a piece of code if the condition is `true`. + +An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. + +`if-else` statements can be chained. + +```javascript +let number = 3; + +if (number > 3) { + console.log(number, "is greater than 3"); +} else if (number < 3) { + console.log(number, "is smaller than 3"); +} else { + console.log(number, "is equal to 3"); +} +``` diff --git a/glossary/javascript/js-while-loop.md b/glossary/javascript/js-while-loop.md new file mode 100644 index 0000000000..1524b1c3a6 --- /dev/null +++ b/glossary/javascript/js-while-loop.md @@ -0,0 +1,16 @@ +# While + +A `while` loop is used when you want to execute a piece of code repeatedly. + +```javascript +let number = 0; + +// while (condition) is true +while (number < 5) { + // Increase number by 1 + number++; + + // Output current value of number + console.log(number); +} +``` \ No newline at end of file diff --git a/glossary/python/python-for-in-range.md b/glossary/python/python-for-in-range.md new file mode 100644 index 0000000000..fa620d7e4f --- /dev/null +++ b/glossary/python/python-for-in-range.md @@ -0,0 +1,19 @@ +# For & range() + +You can use `range()` with a `for..in` loop to cycle through a specified range. + +```python +# For every number in the range 1 to 6 (1 included, 6 excluded) +for number in range(1, 6): + # number to the power of number + print(number ** number) +``` + +Which gives the output: +```plain-text +1 +4 +27 +256 +3125 +``` \ No newline at end of file diff --git a/glossary/python/python-for-in.md b/glossary/python/python-for-in.md new file mode 100644 index 0000000000..33eb7d818e --- /dev/null +++ b/glossary/python/python-for-in.md @@ -0,0 +1,21 @@ +# For...in + +A `for...in` loop is used when you want to iterate over a list, tuple, dictionary, and so on. + +```python +numbers = [1, 3, 2, 5, 9, 4, 7] + +for num in numbers: + print(num) +``` + +The output looks like this: +```plain-text +1 +3 +2 +5 +9 +4 +7 +``` \ No newline at end of file diff --git a/glossary/python/python-function-creation.md b/glossary/python/python-function-creation.md new file mode 100644 index 0000000000..0854afafde --- /dev/null +++ b/glossary/python/python-function-creation.md @@ -0,0 +1,13 @@ +# Function + +Functions are pieces of code designed for a particular task. + +Functions are executed by performing a function call. + +```python +def addition(x, y): + return x + y # Returns the sum of x and y + +# Function called with values for x and y +addition(11, 3) +``` \ No newline at end of file diff --git a/glossary/python/python-if-elif.md b/glossary/python/python-if-elif.md new file mode 100644 index 0000000000..e8051dfdca --- /dev/null +++ b/glossary/python/python-if-elif.md @@ -0,0 +1,18 @@ +# If else + +An `if` is a conditional statement that executes a piece of code if the condition is `true`. + +An `else` statement is used after the `if` and it executes the code if the `if` condition evaluates to `false`. + +`if-else` statements can be chained. + +```python +number = 3 + +if (number > 3): + print("number is greater than", number) +elif (number < 3): + print("number is smaller than", number) +else: + print("number is equal to", number) +``` diff --git a/glossary/python/python-while-loop.md b/glossary/python/python-while-loop.md new file mode 100644 index 0000000000..325116c5dc --- /dev/null +++ b/glossary/python/python-while-loop.md @@ -0,0 +1,19 @@ +# While + +A `while` loop is used when you want to execute a piece of code repeatedly. + +```python +# Ask user for input +number = int(input("Enter a number: ")) + +product = 2 +counter = 1 + +while counter <= number: + # Multiply product by itself + product *= product + # Increase counter + counter = counter+1 + +print("The product is", product) +``` \ No newline at end of file