Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3481870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:29:43+00:00 2026-05-18T10:29:43+00:00

I am currently learning c# and reading a few books. I can do quite

  • 0

I am currently learning c# and reading a few books. I can do quite a few things, however only from modifying examples – it really frustrates that I do not actually understand how/why some of the more basic items work.

I have just done a console application that takes arguments and displays them all one by one.

The code is:

using System;

class test
{ static int Main(string[] argsin)
{ 

for (
        int i = 0; 
        i < argsin.Length; 
        i++
    )
Console.WriteLine("Argument: {0}", argsin[i]);
Console.ReadLine();
return -1;
}
}

Now, this works perfectly, but coming from a basic (no pun!) understand of Visual Basic, how/why does it know to print the correct argument and then go on to the next without quitting the application after the first Console.WriteLine… I feel I have missed the fundamentals of how this works!

Next, why is it that inside the for loop, each line ends with a semicolon apart from i++?

I keep forgetting to add it from time to time, and then when trying to work out why it wasn’t compiling, I added one where I wasn’t meant to!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:29:43+00:00Added an answer on May 18, 2026 at 10:29 am

    By convention c# and all c like languages when presented with a for loop (or and if statement etc) will run the line immediately after. Personally I don’t like writing code like this, i feel it lacks readability.

    To clarify we can add curly braces to denote scope

    for (
            int i = 0; 
            i < argsin.Length; 
            i++
        )
    {
         Console.WriteLine("Argument: {0}", argsin[i]);
    }
    Console.ReadLine();
    return -1;
    

    now what the for loop executes is clearly defined (and if we wanted to do more in our loop we would add the extra instructions in between the curly braces).

    edit:
    The reason for the semi colons as you define your for loop is that each part of that definition is a separate statement.

    int i = 0; //creates an integer i and sets its value to 0
    i < argsin.Length; sets our comparison operation to define when the loop ends
    i++ //what to do at the end in this case increment i by 1
    

    Each needs to be treated independent of the others and as the semi colon denotes the end of a statement in c# (which is why each line ends in it) we use it to break up the statements so the compiler can read it.

    While the 2 semicolons are mandatory the arguments are not we could if we wanted change it to be this.

    int i = 0;
    for (;;)
    {
         if(i>=argsin.Length){
             break;
         }
         Console.WriteLine("Argument: {0}", argsin[i]);
         i++;
    }
    

    This is functionally identical to the way you wrote it but I’ve moved all the logic out of the for statement to its equivalent position inside (or outside in the case of defining i) the loop

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently going though the process of learning C++ though reading programming books.
I'm currently learning F# and I really love the yield! (yield-bang) operator. Not only
I'm currently learning C from some Harvard screencasts. They're great. I'm currently, because I'm
I'm very new to C++ and I'm currently learning it. I got a few
I'm currently reading Artificial Intelligence: A Modern Approach (Russell+Norvig) and Machine Learning (Mitchell) -
I'm currently reading Oreilly's Learning XNA 4.0 and I've noticed that the author is
I am currently still learning PHP so some things I still struggle with. I
I'm quite new to WCF currently studying Learning WCF. Maybe I missed something while
So I am currently reading a book on learning java and a program outlined
I'm currently learning about jsf 2.0 from core jsf 2.0 book + glassfish +

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.