-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.js
82 lines (62 loc) · 1.31 KB
/
loops.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var result = ''
let i = 15
// simple loop...
for(let i=0; i<10; i++)
{
result+= 'i='+i+"\n"
}
console.log(result)
// here i equals 15
console.log('the var i continues with the value ',i)
/* editing again, more examples of JS loops... :-) */
result = ''
const person = {firstName:'Hello',lastName:'World',email:'hello@world.hw'}
for(let x in person)
{
result += person[x]+' | '
}
console.log('object data = ',result)
result = ''
const children = ["João","Otavio","Antonia"]
for(let x in children)
{
result += children[x]+' | '
}
console.log('items of an array = ',result)
var qty = 0;
const lastName = 'VOIGT'
for(let x in lastName)
{
qty+=1;
}
console.log("size of '",lastName,"' is ", qty, ' or ', lastName.length)
/* while example... */
var x = 0;
result = ''
while (x < lastName.length)
{
let letter = lastName[x]
result += `| ${x} = ${letter} | \n`
x++;
}
console.log(result)
/* bubble sort... */
for(let i = 0; i< children.length-1; i++)
{
for(let j=i; j<children.length; j++)
{
if(children[i] > children[j])
{
var aux = children[i]
children[i] = children[j]
children[j] = aux;
}
}
}
result = ''
for (const x of children)
{
result += 'filho ' + x + "\n"
}
console.log(result)
/* below let an empty line... :-/ */