You are here:

C/for loop

Advertisement


Question

(1)
for(i=0;i<100;i++)
{
  for(j=0;j<1000;j++)
   {

   }
}

(2)

for(i=0;i<1000;i++)
{
  for(j=0;j<100;j++)
   {

   }
}

which one is mpre convinient to use and why?


Answer
I am not able to understand your question!
Everything depends on the context.
First one can be convenient for me and Second one could be easier for you!

Looks like somebody asked you this Q, in an interview!

First of all you must understand that, Between the first loop and second loop, there can be many more statements.
In that case, the first and second will produce completely different output.

And if you want to know which is faster, everything depends on the compiler.
From C language perspective, both are same.
It is the compiler, operating system and the underlying hardware, that makes the difference.

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.