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 181097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:42:06+00:00 2026-05-11T14:42:06+00:00

I though that I know this one… I had no clue. This simple For

  • 0

I though that I know this one… I had no clue.

This simple For loop:

Dim i As Integer Dim n As Integer = 10 Dim s As Integer = 1  For i = 0 To n Step s     Console.WriteLine(i) Next 

compiles into this (I put it through Refelctor, so it’s easier to read). I couldn’t even get what it does with all these bit-shifts:

Dim n As Integer = 10 Dim VB$t_i4$L1 As Integer = 1 Dim VB$t_i4$L0 As Integer = n Dim i As Integer = 0 Do While (((VB$t_i4$L1 >> &H1F) Xor i) <= ((VB$t_i4$L1 >> &H1F) Xor VB$t_i4$L0))     Console.WriteLine(i)     i = (i + VB$t_i4$L1) Loop 

Why For loop is mutilated like this?

  • 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. 2026-05-11T14:42:06+00:00Added an answer on May 11, 2026 at 2:42 pm

    Probably because it’s the ‘generic way’ to cover all cases. Remember that for/step/next can go in any direction with any sign on the increment.

    You used parameters on both the increment and the end-bound. The compiler has no way to know if you are going to count up or down, and if th end-bound is higher or lower than the start bound.

    My guess is this is a way to get code that will work whatever you put in n and s (just a guess, I’m too tired to try and see if that is the case).

    Also it makes copies of the parameters to prevent outside interference (like changing s or n during the enumeration).

    === UPDATE ===

    I doubt anybody is still watching that question but I came back to this nugget just for the sake of completeness, and because I had some time. What VB is doing is a bit sneaky. The bit shift of S basically creates an integer based on the sign of S (it copies the MSB of s, ending up with &hFFFFFFFF is S is negative and &h00000000 if S is positive).

    XOR of an integer value with -1 is equivalent to (-value-1). XOR with 0 is obviously a NOP. So if s is negative, it reverses both values (the -1 cancel each other) to compare them, effectively reversing the order of comparison without the need or a conditional, and thus no jump in the program flow. If s is positive it just compares them.

    so, for s<0 you end up with

    while (-i-1)<=(-n-1)  ==> while -i <= -n ==> while i>=n 

    for s>0 you end up with

    while i <= n 

    Takes me back to my 68k ASM days where such tricks where the everyday stuff (such as XOR.l D0,D0 because XORing a register with itself was faster than loading zero in it…) :p

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

Sidebar

Ask A Question

Stats

  • Questions 174k
  • Answers 174k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you're looking for Ctrl + F2, which moves… May 12, 2026 at 2:51 pm
  • Editorial Team
    Editorial Team added an answer How about potentially a view based on the aggregates, possibly… May 12, 2026 at 2:51 pm
  • Editorial Team
    Editorial Team added an answer As far as I know, you can open a project… May 12, 2026 at 2:51 pm

Related Questions

I though that I know this one... I had no clue. This simple For
One thing that really interests me that I don’t see much written about or
Alright I have an xml document that looks something like this: <xml> <list> <partner>
I built a small website and there will be only one admin, so in
I have a function that pulls rows from a database, the content->id and content->type

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.