0
can I please know how to improve in programming ...it's always difficult for me to understand for loop for example:(I<1;I<=10;I++);
6 Answers
+ 1
It is difficult because you start with a wrong thing
--> for(I<1;I<=10;I++);
The correct thing should be
for(I=1;I<=10;I++);
0
You wouldn't do I < 1, that wouldn't make sense. Think of a for loop like a counter. You start with what you're counting and what you are starting at. You then follow it with when you want your counter to end. Finally, you set how your counter counts. For example, we want to count to 10. Start at 0 and go up by 1. You'd do (int i = 0; i <= 10; i++). Let's say you want to go to 10 in increments of 2, starting with 2. Then it would be like (int counter = 2; counter <= 10; counter += 2).
0
You can improve your skills in programming only if you are practicing it daily....here is the solution first choose one programming language in which you want to excel then build your logic by solving some problems for eg. go for sorting and searching techniques, some mathematical problems, puzzles...make habit of solving it daily...once the logic is build you can code in any language only thing you will need to know will be syntax.
0
I think of it like this.... In my head i would read a loop of this nature "for(int i=0;i<10;i++) { // do something }" "for int i=0" .. Which initializes your local variable i to zero.. So in incrementing througout the loop, the for loop adds to the i variable. "i<10".. This is the boolean(true or false) the loop will check to see if it has properly fullfilled as true, happening at each iteration of the loop. So i read it as "starting at i, while i is less than 10" ... "i++" .. This is the value that is added to upon each iteration.. In other words
for the first loop, i=0. After the loops body has been finished, the loop goes back into the "for(int i=0;i<10;i++)" statement.. BUT.. Instead of int i=0; NOW int i=1, and the for loop statement will now check to see it i is less then 10 --> "1<10" replacing the variable i for its value of 1. It does this over and over, incrementing the i variable at the end of each loop, and while the boolean "i<10" is true, it will keep entering the loop until i is no longe less than 10... Recall your logical operators from an earlier section and math class and make sure you have a solid knowledge on "<,<=,>,=>" operators!
0
for( initial value; condition; increment)
Example:
for(int number = 0: number<10; number++)
{
System.out.println(number); //body
}
Output:
0
1
2
3
4
5
6
7
8
9
_____________
For each iteration of the loop, starting at 0; and while number y less(<) than 10(9); print the number(body) and add 1 to the number.
0
There three things to any loop, initialization i.e. i=0, termination guarantee like i < 10 that ensures that your loop will terminate at some point then an update statement such as i++ to increment the initial value, i= 0 and if you were following along this would print 0 - 9, in set notation [0-10) with 10 exclusive since our termination guarantee is < 10.