+ 3
Is it good to use more than 10 nested loop?
36 ответов
+ 14
You can! But, time complexity increases with level of nesting. So, try to avoid high levels of nesting.
+ 5
hargun is asking about nested loops - presumably meaning along the lines of (psuedo code):
for i > 10
for j > 10
for k > 20
etc
c++ isnt one of my languages (atm anyway) but usually switch replaces ifs why are people talking about switch???
+ 4
I can't be sure if it's necessarily bad, but it's definitely not good. You should use switch instead.
+ 4
It is possible but not good?
I forbid more than three because
- nobody will understand three days later
- it is normally an indicator for bad structured programs.
- memory problems (well those were the days)
the solution are indeed modules.
you might still have hidden deep nested loops finally but... well nothing is perfect
+ 4
A recursive function would be much better in terms of time execution, think about it, let's say with two loops it takes O^2 time. For 10 loops it's O^10. For example, let's say it takes you 2 seconds to compute with a single loop. With 10 loops it takes 2^10 seconds (more precisely 1024 seconds).
+ 4
It is possible but it may confuse you and may cause bug if logic isn't right
+ 3
I'm sorry but I disagree to those people who say a switch statement is equivalent to 10 loops....Both have different functionality.But making 10 loops increasing runtime speed and I don't see where u can make use of it
+ 3
it will definitely slow down the execution speed of your program
+ 3
Try write Your problem on a paper sheet and reduce it matematically.
Try to look on every loop like on dimention. Maybe You need read something about permutations also?
+ 2
NOOOOO, hope that helps.
+ 1
try to use switch, conditional statement,and recursion to avoid complexity
+ 1
You can ....
but it is not good because it will be as a stuff for compiler or we can say for CPU.👀
+ 1
No. Complexity will be n^10. Try to achieve with recursion
why you required 10 nested loops?
+ 1
Don't use anested loop too much as it increases complexity . You won't be able to understand your own program. Use switch with for loop . I think it would be easy and help you.
+ 1
Actually it is not advisable to use more than 10 nested loops because of the following reasons:
->It leads to exponential time which makes your code unusable
->It leads to cyclomatic complexity which means it is very hard to maintain this code.
->It leads to polynomial complexity that means it takes many iterations which may be or may be not required at all.
It's ok to use 3 nested loops because it's easy and popular also and also can be considered but increasing the nesting is not a good idea.
You can go for better options like hash tables which has better time complexity.
You can also go for switch statements,conditionals or recursions as well.
+ 1
it increase the program complexity and decrease performance also
0
I do agree with the fellows who advised to use Switch case. It makes more sense to use a switch once you start having more than 2 conditions to check. A switch also allows better human readability (As opposed to having a lot of loops).
0
Where do you use 10 dimensional array?
0
It is not a good programming practice. I will not recommend more than three.
Try functional programming. Create functions and pass values as argument. this makes your code readable, easy to maintain and also reusable
0
I think it depends on why do u need it. If you have only solution to solve the matter then it is good for use but if you find other way to solve then you have to consider performance matter as other says switch or other methods.