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

  • SEARCH
  • Home
  • 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 4564152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:27:37+00:00 2026-05-21T18:27:37+00:00

In the book I’m reading _Pro C# 2008 and the .NET Platform there is

  • 0

In the book I’m reading _Pro C# 2008 and the .NET Platform” there is a chapter on CIL with some code that I am confused about.

enter image description here

Why is the step highlighted necessary? As I see it, this is what the code is doing.

  1. A local integer variable “i” is created and is initialized to 0 (by virtue of integers are always initialized to 0 if not explicitly assigned a value)
  2. (IL_0000) The value of the local variable [0] (which is “i”) is loaded onto the stack
  3. (IL_0001) Then the value is popped off the stack and assigned to “i” again . . . WHY? “i” is already 0!
  • 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-21T18:27:38+00:00Added an answer on May 21, 2026 at 6:27 pm

    From a memory standpoint, you could consider the initialization of i to 0 unnecessary, as the default value of an initialized int32 variable is 0.

    However, the compiler is preserving the semantic information of the loop in the source code. The variable i is, after all, assigned to 0 in the for statement, and this information ends up serialized in the IL. It’s likely that this statement will be optimized away by the JIT anyway. At least Mono’s JIT does so. From the CIL standpoint it makes it easy to see what’s happening:

    .locals init (int32 i)
    
    ldc.i4.0
    stloc.0
    
    // i = 0
    
    br.s loop_test
    
    loop_body:
        ldloc.0
        ldc.i4.1
        add
        stloc.0
    
        // i = i + 1
    
    loop_test:
        ldloc.0
        ldc.i4.s  10
        blt.s loop_body
    
        // i < 10  
    
    ret
    

    At the CIL level, a for is basically:

    • a pre-tested loop (the condition is tested before the body is first executed, hence the br, an unconditional branch),
    • variable initializers before the loop body,
    • operations on the initialized variables at the end of the body.

    It’s quite easy to visually identify the different for elements in the CIL above.

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

Sidebar

Related Questions

In the The Django Book in chapter 6 about the Admin Site, they tell
I am reading a book about Javascript and jQuery and using one of the
The book I'm reading about Erlang has exercises in the back of it and
The book I've been reading about Django mandates heavy usage of a command line
A book I was reading, on sql server 2008, mentions how you should not
The book Agile development with Rails shows in the second chapter, that you can
The book I am reading says that SQL Server supports two kinds of character
The book I'm currently reading has me write the following code : -(IBAction)displaySomeText:(id)sender {
My book presents a simple example which I'm a bit confused about: It says,
I am reading a book for Java that I am trying to learn, and

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.