Click here to Skip to main content
15,921,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to use WM_PASTE ? Pin
OriginalGriff1-Oct-13 6:01
mveOriginalGriff1-Oct-13 6:01 
GeneralRe: How to use WM_PASTE ? Pin
Mahmoud EL-Shazly1-Oct-13 9:35
Mahmoud EL-Shazly1-Oct-13 9:35 
AnswerRe: How to use WM_PASTE ? Pin
Simon_Whale1-Oct-13 3:30
Simon_Whale1-Oct-13 3:30 
QuestionOOPS, deisgn patterns and principles Pin
Govindaraj Rangaraj1-Oct-13 0:25
Govindaraj Rangaraj1-Oct-13 0:25 
QuestionRe: OOPS deisgn patterns and principles Pin
Eddy Vluggen1-Oct-13 0:31
professionalEddy Vluggen1-Oct-13 0:31 
AnswerRe: OOPS deisgn patterns and principles Pin
Keith Barrow1-Oct-13 1:01
professionalKeith Barrow1-Oct-13 1:01 
AnswerRe: OOPS deisgn patterns and principles Pin
Abhinav S1-Oct-13 1:17
Abhinav S1-Oct-13 1:17 
GeneralRe: OOPS deisgn patterns and principles Pin
Govindaraj Rangaraj1-Oct-13 4:14
Govindaraj Rangaraj1-Oct-13 4:14 
GeneralRe: OOPS deisgn patterns and principles Pin
Eddy Vluggen1-Oct-13 5:00
professionalEddy Vluggen1-Oct-13 5:00 
AnswerRe: OOPS, deisgn patterns and principles Pin
GuyThiebaut1-Oct-13 21:47
professionalGuyThiebaut1-Oct-13 21:47 
GeneralRe: OOPS, deisgn patterns and principles Pin
Keith Barrow2-Oct-13 0:32
professionalKeith Barrow2-Oct-13 0:32 
QuestionArrays Pin
Sta_Horse30-Sep-13 23:35
Sta_Horse30-Sep-13 23:35 
AnswerRe: Arrays Pin
Garth J Lancaster30-Sep-13 23:50
professionalGarth J Lancaster30-Sep-13 23:50 
GeneralRe: Arrays Pin
harold aptroot1-Oct-13 1:47
harold aptroot1-Oct-13 1:47 
GeneralRe: Arrays Pin
Garth J Lancaster1-Oct-13 2:10
professionalGarth J Lancaster1-Oct-13 2:10 
AnswerRe: Arrays Pin
Pete O'Hanlon30-Sep-13 23:52
mvePete O'Hanlon30-Sep-13 23:52 
AnswerRe: Arrays Pin
OriginalGriff30-Sep-13 23:52
mveOriginalGriff30-Sep-13 23:52 
You presumably know how a for loop works - but I'll recap just in case:
C#
for (init; test; alter)

Where:
init sets up the initial conditions - in your case, it sets i or j to zero.
test checks to see if the loop should continue - if test is true, it will.
alter allows you to modify the conditions so the the test will eventually become false.

So in your first loop, the value of i changes by one each time (in the second loop, the same thing happens to j) so each time the loop executes, it accesses a different element of teh array, and sets it to a different value.

For the second loop, it outputs each element in sequence.
There is no particular reason why the person who wrote that used separate variables i and j for the two loops - probably just for clarity - they could be the same variable without affecting the rest of the code.

Personally, I would change it slightly and declare the loop guard variable inside the loop:
C#
static void Main(string[] args)
    {
    int[] n = new int[10];
    //initialize elements of array n
    for (int i = 0; i < 10; i++)
        {
        n[i] = i + 100;
        }

    // output each array element's value
    for (int j = 0; j < 10; j++)
        {
        Console.WriteLine("Element [{0}] = {1}", j, n[j]);
        }
    Console.ReadKey();
    }
As this makes it clearer that i and j are only relevant (or indeed available) inside the loop. Again, the name i could be used for both loops:
C#
static void Main(string[] args)
    {
    int[] n = new int[10];
    //initialize elements of array n
    for (int i = 0; i < 10; i++)
        {
        n[i] = i + 100;
        }

    // output each array element's value
    for (int i = 0; i < 10; i++)
        {
        Console.WriteLine("Element [{0}] = {1}", i, n[i]);
        }
    Console.ReadKey();
    }

The only instant messaging I do involves my middle finger.

AnswerRe: Arrays Pin
V.1-Oct-13 2:22
professionalV.1-Oct-13 2:22 
QuestionHow can i do a calculation in datagridview Pin
ganesh89_babu30-Sep-13 20:40
professionalganesh89_babu30-Sep-13 20:40 
AnswerRe: How can i do a calculation in datagridview Pin
Abhinav S30-Sep-13 22:35
Abhinav S30-Sep-13 22:35 
QuestionHow to extract links from a div Pin
faiza.butt8930-Sep-13 14:53
faiza.butt8930-Sep-13 14:53 
GeneralRe: How to extract links from a div Pin
PIEBALDconsult30-Sep-13 15:02
mvePIEBALDconsult30-Sep-13 15:02 
AnswerRe: How to extract links from a div Pin
Abhinav S30-Sep-13 17:15
Abhinav S30-Sep-13 17:15 
GeneralRe: How to extract links from a div Pin
faiza.butt891-Oct-13 4:16
faiza.butt891-Oct-13 4:16 
AnswerRe: How to extract links from a div Pin
Akii Malam1-Oct-13 1:32
Akii Malam1-Oct-13 1:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.