Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Learning JavaScript
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MohammadAli Keshavarz
Learning JavaScript
Commits
c341638e
Commit
c341638e
authored
Oct 13, 2019
by
MohammadAli Keshavarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Loops and iteration
parent
914b11a1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
1 deletion
+44
-1
script.js
script.js
+44
-1
No files found.
script.js
View file @
c341638e
...
@@ -348,7 +348,7 @@ console.log(jane);
...
@@ -348,7 +348,7 @@ console.log(jane);
/*****************************
/*****************************
* Objects and methods
* Objects and methods
*/
*/
/*
var john = {
var john = {
firstName: 'John',
firstName: 'John',
lastName: 'Smith',
lastName: 'Smith',
...
@@ -362,5 +362,48 @@ var john = {
...
@@ -362,5 +362,48 @@ var john = {
};
};
john.calcAge();
john.calcAge();
console.log(john);
console.log(john);
*/
/*****************************
* Loops and iteration
*/
// for loop
for
(
var
i
=
1
;
i
<=
20
;
i
+=
2
)
{
console
.
log
(
i
);
}
// i = 0, 0 < 10 true, log i to console, i++
// i = 1, 1 < 10 true, log i to the console, i++
//...
// i = 9, 9 < 10 true, log i to the console, i++
// i = 10, 10 < 10 FALSE, exit the loop!
var
john
=
[
'John'
,
'Smith'
,
1990
,
'designer'
,
false
,
'blue'
];
for
(
var
i
=
0
;
i
<
john
.
length
;
i
++
)
{
console
.
log
(
john
[
i
]);
}
// While loop
var
i
=
0
;
while
(
i
<
john
.
length
)
{
console
.
log
(
john
[
i
]);
i
++
;
}
// continue and break statements
var
john
=
[
'John'
,
'Smith'
,
1990
,
'designer'
,
false
,
'blue'
];
for
(
var
i
=
0
;
i
<
john
.
length
;
i
++
)
{
if
(
typeof
john
[
i
]
!==
'string'
)
continue
;
console
.
log
(
john
[
i
]);
}
for
(
var
i
=
0
;
i
<
john
.
length
;
i
++
)
{
if
(
typeof
john
[
i
]
!==
'string'
)
break
;
console
.
log
(
john
[
i
]);
}
// Looping backwards
for
(
var
i
=
john
.
length
-
1
;
i
>=
0
;
i
--
)
{
console
.
log
(
john
[
i
]);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment