+ 2
loop within a loop
so friends i get confused sometimes when to use 2 loops inside main loop or when to use 3. for example in case of bubble sorting we use 2 loops and in case of printing the pyramid we use 3 loops. so basically how do we get to know that a problem requires one loop , 2 loop , 3 loops etc within a loop.
2 Respuestas
+ 2
i think you should first of all think About problem until.you.understand what u need.
for example, you want to see whether there is a number in.array or not, so you need one loop,but if you need search in matrix, you need 2 loop... one for cols and one for rows
, but if you want search in special method like bubble, you need more... because you do search for sort first element with one loop, then repeat it for remaining elements
.
+ 1
When you have two loops say i being outermost loop and j being an innermost loop, first the value of i is set and j is incremented for all possible values according to the condition you specify. Then i is incremented and set and all values of j is seen.