-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforVSwhile_loop.js
More file actions
44 lines (32 loc) · 873 Bytes
/
forVSwhile_loop.js
File metadata and controls
44 lines (32 loc) · 873 Bytes
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
/*
// for loop is suitable when initial and end points are known
for(var i = 1; i<=100; i++){
if(i%3 === 0){
console.log(i);
}
}
*/
// while loop is suitable when end point is not known. Loop stops by condition.
num = 8545651;
// console.log(num%10);
// num = parseInt(num/10);
// console.log(num);
// console.log(num%10);
// num = parseInt(num/10);
// console.log(num);
while(num>0){
console.log(num%10);
num = parseInt(num/10);
//console.log(num);
}
// for this problem we don't know what would be the strat and the iteration in for loop
/*
let n = 1729;
while(n!=6174){
min_n = parseInt(n.toString().split('').sort().join(''));
max_n = parseInt(n.toString().split('').sort((a,b)=>b-a).join(''));
diff = max_n - min_n;
console.log(min_n, max_n, diff);
n = diff;
}
*/