Skip to content

Commit 501b657

Browse files
added new for loop and while loop problem
1 parent f420492 commit 501b657

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
8+
9+
{
10+
"type": "node",
11+
"request": "launch",
12+
"name": "Launch Program",
13+
"skipFiles": [
14+
"<node_internals>/**"
15+
],
16+
"program": "${workspaceFolder}\\skip-odd.js"
17+
}
18+
]
19+
}

D. Loop/Continue/skip-five.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* Problem-2
2+
display odd number from 55 to 85 and skip the numbers divisible by 5.
3+
*/
4+
// Solution-1 by While loop
5+
let i = 55;
6+
while (i <= 85) {
7+
i++;
8+
if (i % 2 === 0 || i % 5 === 0) {
9+
continue;
10+
}
11+
console.log(i);
12+
}
13+
14+
// Solution-2 by for loop
15+
for (let j = 55; j <= 85; j++) {
16+
if (j % 2 === 0 || j % 5 === 0) {
17+
continue;
18+
}
19+
console.log(j);
20+
}

D. Loop/Continue/skip-odd.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Problem-1
2+
Write a loop to print even numbers from 1 to 40. Use continue to skip odd numbers.
3+
*/
4+
5+
// Solution-1 by While loop
6+
let i = 1;
7+
while (i <= 40) {
8+
i++;
9+
if (i % 2 === 1) {
10+
continue;
11+
}
12+
console.log(i);
13+
}
14+
15+
// Solution-2 by for loop
16+
17+
for (let j = 1; j <= 40; j++) {
18+
if (j % 2 === 1) {
19+
continue;
20+
}
21+
console.log(j);
22+
}

0 commit comments

Comments
 (0)