I have gone through this Question and Answer While loop inside while loop JavaScript
function getMaxLessThanK(n, k) {
let i = 1;
while (i < n) {
let j = i + 1;
while (j < n + 1) {
console.log(i, j)
j++
}
i++
}
}
when n = 5, what am I getting is
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
undefined
How to avoid this the last line undefined. what is the reason for it?
Can anyone help on this please?
Edit:
This is what the actual thing I am doing below.



console.log(getMaxLessThanK(5))? Your function returnsundefined.n =5, k=4, console.log(getMaxLessThanK(n)undefined. This is the answer you are looking for.undefinedis not an unexpected value.