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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:19:31+00:00 2026-05-14T22:19:31+00:00

Our computer science teacher once said that for some reason it is faster to

  • 0

Our computer science teacher once said that for some reason it is faster to count down than to count up.
For example if you need to use a FOR loop and the loop index is not used somewhere (like printing a line of N * to the screen)

I mean that code like this:

for (i = N; i >= 0; i--)  
  putchar('*');  

is faster than:

for (i = 0; i < N; i++)  
  putchar('*');  

Is it really true? And if so, does anyone know why?

  • 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-14T22:19:32+00:00Added an answer on May 14, 2026 at 10:19 pm

    Is it really true? and if so does anyone know why?

    In ancient days, when computers were still chipped out of fused silica by hand, when 8-bit microcontrollers roamed the Earth, and when your teacher was young (or your teacher’s teacher was young), there was a common machine instruction called decrement and skip if zero (DSZ). Hotshot assembly programmers used this instruction to implement loops. Later machines got fancier instructions, but there were still quite a few processors on which it was cheaper to compare something with zero than to compare with anything else. (It’s true even on some modern RISC machines, like PPC or SPARC, which reserve a whole register to be always zero.)

    So, if you rig your loops to compare with zero instead of N, what might happen?

    • You might save a register
    • You might get a compare instruction with a smaller binary encoding
    • If a previous instruction happens to set a flag (likely only on x86 family machines), you might not even need an explicit compare instruction

    Are these differences likely to result in any measurable improvement on real programs on a modern out-of-order processor? Highly unlikely. In fact, I’d be impressed if you could show a measurable improvement even on a microbenchmark.

    Summary: I smack your teacher upside the head! You shouldn’t be learning obsolete pseudo-facts about how to organize loops. You should be learning that the most important thing about loops is to be sure that they terminate, produce correct answers, and are easy to read. I wish your teacher would focus on the important stuff and not mythology.

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

Sidebar

Related Questions

So our computer science teacher taught us how to convert int s to String
Our support team has diagnosed some specific areas of a computer's configuration that may
I need to get the local Computer Name for a desktop computer running our
Our company is using some software that ONLY accepts input from an Imaging Device
How to install Android in our Computer(linux-Fedora ,Windows -XP) ,and I need to run
We have a web application that manages inventory for our computer support group. One
I am trying to combine some info from our Active directory - computer names,
I work in an engineering lab, not a computer science lab. As such, our
Why is it important to assume that integers in our computer model have a
This is our CMIS(Computer Management Information System) Server page: (Note: The CMIS server I

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.