For Loop
xxxxxxxxxx
for (expression 1; expression 2; expression 3) {
// code block to be executed
}
Example of For Loop
xxxxxxxxxx
for(let i = 0; i < arr.length; i++){
// code block to be executed
}
For In Loop
xxxxxxxxxx
for (key in object) {
// code block to be executed
}
Example of For In Loop
xxxxxxxxxx
for (let x in arr) {
// code block to be executed
}
For Of Loop
xxxxxxxxxx
for (variable of iterable) {
// code block to be executed
}
Example of For Of Loop
xxxxxxxxxx
for (let x of arr) {
// code block to be executed
}
While Loop
xxxxxxxxxx
while (condition) {
// code block to be executed
}
Example of While Loop
xxxxxxxxxx
while (i < 10) {
// code block to be executed
i++;
}
xxxxxxxxxx
# You can easily install mongodb to run locally on your windows machine using chocolatey
# run
$ choco install mongodb
# to properly set up, add the mongodb path -- in my case it is; C:\Program Files\MongoDB\Server\5.3\bin -
# to your system environment variables
# then test your installation
$ mongo --version
# expected output
# MongoDB shell version vx.y.z
# Build Info: {
# "version": "x.y.z",
# "gitVersion": "ea201bb0ab5fa4c9c9d27c29a538987db15c0a36",
# "modules": [],
# "allocator": "tcmalloc",
# "environment": {
# "distmod": "windows",
# "distarch": "x86_64",
# "target_arch": "x86_64"
# }
#}
xxxxxxxxxx
for - loops through a block of code a number of times
for/in - loops through the properties of an object
for/of - loops through the values of an iterable object
while - loops through a block of code while a specified condition is true
do/while - also loops through a block of code while a specified condition is true
for (let i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
xxxxxxxxxx
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.2.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
$ sudo service mongod status
mongod start/running, process 3627
$ mongo --version
MongoDB shell version v4.2.8
git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
$
$ pip3 install pymongo
$ python3
>>> import pymongo
>>> pymongo.__version__
'3.10.1'