+ 18
Easiest way to Solve loops?
I am good at programming concept but when I see a loop I have to spend time for understanding loop. Is there any faster way to solve this problem
29 Antworten
+ 19
I usually make flowcharts to understand it... However if there are simple loops, I try to make everything into my mind. I do that to train myself, even if I find it hard.
+ 18
I try to understand a loop by reading it from inner to outer. First the statements in the inner loop. Then I check how often that statement is executed by understanding the loop conditions. Then one level up and check statements in the nesting loop if there are any. Then conditions of the nesting loop and so on. Sometimes it is enough to find out how often inner loop and nesting loops are iterated to understand what trey are doing. The resulting number of iteration is then (iter inner)*(iter outer).
Sorry I can't tell any cheats, it always depends on the loops, if there is an easier way.
+ 11
I am going to assume you mean for loops since ppl generally have a hard time with those. As far as understanding the process of the loop, it's as follows:
1. variable initialization
2. condition
3. body
4. increment/ decrement
5. back to step 2 until loops ends
continue will skip the body execution of that instance
break will exit the entire loop
with nested loops, inner most loop does complete cycle per # of iterations of outer most loop O(N)^2
+ 11
just have a look at the condition and the inner code then it will be easy to understand the code. It will also reduce the time taken by you in understanding the whole loop.
+ 8
It's just a matter of practice
+ 7
try to read statements one at a time
+ 7
Practice makes a man perfect...
practice more and more for it
+ 6
understand the algorithm and practice more loops .....in the beginning you would require a practical approach and would take more time but then you could understand the working of loops faster and easily
+ 6
Last resort : stick to using it by examples etc and you will eventually understand it !
+ 5
There isn't
because you need to understand how is it going to work at each step with increments or decrements.
+ 5
Just make some points like
1. Conditions for loop to come out.
2. How many times your loop should run
3. Variable that checks the loop conditions
4. How many !oops you require
5. whether loop inside the loop makes the task simple
such points will help you solve loop. All the best.
+ 5
you have to fully concentrate on the given condition.
+ 5
Let's take a example:
1
2 2
To generate this output, take it as problem statement, make a flowchart which will help in understanding better. Then write a program with loops. Consider distribute variables as primary and secondary or say inner and outer loop variables.
In this case we can see there is number of integers increase as line number increases. Also as line number increases value of Integers are also increasing. So we consider outer loop variable as line number and remaining variables as inner loop variables. Similarly each problem can be solved easily by using flowchart and using this method.
+ 5
while(!understand)
{spend time practicing over different examples}
+ 4
see online lectures about loop
+ 4
Loop is very easy. When we execute some specific lines of code for many times. We use loop.
+ 3
like in patterns programming with loops...try to understand what controls what..is it rows values controlling the columns values or vice versa..always read them inside out for the innermost is controlled by the one before it and the level rises.
finish following the execution of the inner first then jump to its follower which is usually it's controller.
+ 3
The way I used is to keep the track of the variables for few iterations to understand the pattern, it helps to get the intuition what the loop really wants to accomplish.
+ 3
easy way to understand loop is to check every thing one by one and move slowly with proper understanding...
and try to modify any simple loop question into difficult one
+ 3
Taking an example of few iterations is a very simple but very effective way.. This will help us know how and the no. of times the loop is working.
This will enable us to write the code for loops to get the desired results..
All the best...!!!