Yes, I'm new but not to programming as I have been working with that for a while. My trouble is loops, I never can get them nor learn how to make them along with arrays. Is there any chance that someone could provide resources like practices for me so I can try to practice them a little more???
Thanks in advanced...
10 replies to this topic
#1
Posted 30 January 2011 - 05:15 PM
|
|
|
#2
Posted 30 January 2011 - 08:20 PM
I do not know so much of Java, so this code may not run, the aspects are correct though.
This example uses an array, and loops through it printing each element.
EDIT: D'oh.. C#..
This example uses an array, and loops through it printing each element.
integer array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
integer i;
for (i = 0; i < 10; i++) {
print array[i]; //will print array[0], array[1] .... array[9]
}You can use a foreach like syntax, which will handle the array looping automatically:integer array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for (integer num as array) {
System.out.println(num); //num will automatically be the next element in "array"
}
EDIT: D'oh.. C#..
Edited by Alexander, 30 January 2011 - 09:18 PM.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 30 January 2011 - 08:23 PM
Im not to sure of any websites like that but I can point you to some tutorials, and give you a small assignment?
http://forum.codecal...ial-arrays.html
http://forum.codecal...-looping-c.html
After you read those tutorials, you could try and make a small program that assigns the value's of an array through a for loop(say it assigns the numbers 1-10 into the array). Then prints it out through another for loop.
Once your done post your code, or if you get stuck show us what you got an we can try to help.
Good luck ~ Committed. :)
http://forum.codecal...ial-arrays.html
http://forum.codecal...-looping-c.html
After you read those tutorials, you could try and make a small program that assigns the value's of an array through a for loop(say it assigns the numbers 1-10 into the array). Then prints it out through another for loop.
Once your done post your code, or if you get stuck show us what you got an we can try to help.
Good luck ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#4
Posted 30 January 2011 - 09:10 PM
Quote
I do not know so much of Java, so this code may not run, the aspects are correct though.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#5
Posted 30 January 2011 - 09:13 PM
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9 ,10};
foreach(int num in array)
{
Console.WriteLine("{0}", num.ToString());
}
Console.ReadLine();
Is this what you were thinking of for an assingment???
#6
Posted 30 January 2011 - 09:20 PM
Quote
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9 ,10};
foreach(int num in array)
{
Console.WriteLine("{0}", num.ToString());
}
Console.ReadLine(); Is this what you were thinking of for an assingment???
Good job! But I ment using a for loop like this(Your loop is called a 'foreach' loop) :
for (i = 0; i < 10; i++) {
//Some code here
}
Hope your learning. BTW the best way to get used to loops it to just work with them, loops confuse newer programmers all the time. ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#7
Posted 31 January 2011 - 12:58 PM
Maybe it's just me but when does the programmer actually learn & use loops without looking or thinking or really any code??? I can do a Console.Writeline & a Console.Readline() without thinking along with a if & then statement but not really a loop statement.
#8
Posted 31 January 2011 - 01:14 PM
All you need is patience. Just keep using them and practicing and you will be able to use them with ease just like Console.Write ect... Another tip if you cant quite remember how the loops it written but dont want to look you can right click and click 'Insert Snippet' then the C# folder, then find the if, do, for, foreach, or while loop and double click it. It will write the loop for you. Just a tip that might help you in remembering the loops.
~ Committed. :)
~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#9
Posted 06 February 2011 - 09:43 PM
Ya, but I learn from just typing it in, not snippets. Yes, patients is what i use but now I got issues such as going into the Airforce & finishing up school too :/
#10
Posted 06 February 2011 - 09:46 PM
Maybe I should rephrase it to, persistence. ;)
Dont worry, and dont give up, and you will reach your goals. ~ Committed. :)
Dont worry, and dont give up, and you will reach your goals. ~ Committed. :)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#11
Posted 13 February 2011 - 09:59 PM
Yes, yes :D
Thank you very much again for the help :D
Thank you very much again for the help :D
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









