473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Loop declaration in C

for (int i =0;i<0;i++)

Is this kind of definition inside for loop is allowed in c standard.
Aug 21 '07 #1
5 1610
kreagan
153 100+
for (int i =0;i<0;i++)

Is this kind of definition inside for loop is allowed in c standard.
no, you cannot create a variable while assigning it a value in C. You can do that for C++ thought

it should be

Expand|Select|Wrap|Line Numbers
  1. int i = 0;
  2.  
  3. for (i = 0; i < number; i++)
Also, your loop will always terminate from the first call because i is always greater than 0;
Aug 21 '07 #2
no, you cannot create a variable while assigning it a value in C. You can do that for C++ thought

it should be

Expand|Select|Wrap|Line Numbers
  1. int i = 0;
  2.  
  3. for (i = 0; i < number; i++)
Also, your loop will always terminate from the first call because i is always greater than 0;
Yup you can create variable like this inside for loop , but your loop has no meaning !!?
Aug 21 '07 #3
somebody give a clear idea if u can or cannot
Aug 22 '07 #4
sicarie
4,677 Expert Mod 4TB
somebody give a clear idea if u can or cannot
I think you need to re-read the thread, your question has been answered.

I also changed the thread title as per the Posting Guidelines to describe your issue.
Aug 22 '07 #5
Banfa
9,065 Expert Mod 8TB
Yup you can create variable like this inside for loop , but your loop has no meaning !!?
This is not true. Note this is a question about C. You can only create a variable in a for loop like that in C++.
Aug 22 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Christophe Grimault | last post by:
Hi all, look at the following code: ////////////////////////// for(int i = 0; i<10; i++) cout << i; for(int i = 0; i<20; i++) cout << i;
12
by: reynoldscraigr | last post by:
Hi All, hope someone can see what wrong here I have the following function function RemoveMenuFromHoldArray(menuName) { var i = 0; for (i=0;i<=MenusToHoldOpen.length-1;i++) { if...
32
by: Wenjie | last post by:
Hello, We had a code review with the argument of whether "i" is out of scope as illustrated below: for (int i=0; i<2004; i++) { doSomething(i); }
14
by: Jim Langston | last post by:
Which is more efficient (if either) MyHugeClass MyObject; for ( int i = 0; i < 1000; ++i ) { MyObject = SomeVal; Use MyObject; }
8
by: Sweety | last post by:
hello, can any one tell why void main() { for(;0;) printf("hello") ; }
8
by: Pedro Pinto | last post by:
When compiling my program i got this error: Error: 'for' loop initial declaration used outside c99 mode What is it and how can i solve it? Thanks in advance! Regards
7
by: Ravi | last post by:
I read from the book "The Complete Reference - C" that C99 allows us to declare for loop variables as for(int i=0; i < 10; i++) printf("%d",i); however, my compiler(gcc) gives me the error:...
9
by: pauldepstein | last post by:
On my visual c++ compiler, I compiled code which contained something like for( int i =0; i < 5; i++) { double x =5;} I expected it to give a compiler error because x is being redefined
12
by: poornimamprabhu | last post by:
Hi there, suppose i have piece of code like main() { int i,j; for(i=0;i<10;i++){ int k = i; printf("%d %p = *%d\n",i,&k,k); }
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.