How to initialize several variables in a for (;;) loop in C? -


I thought someone could start multiple variables in for loop :

 for  (int i = 0, char * ptr = bam; i & lt; 10; i ++) {...}  

but I know just now It's not possible that GCC returns the following error:

  Error: Expected unauthorized-id required before 'four' - is it really true that you have different variables You can not start  for  loop    

you can not start You can (but should not usually) use of a local structure type. {int i; Char * ptr;} loopy = {0, bam}; Loopy.i & lt; 10 & amp; Amp; * For loopy

  Ptr! = 0; ++ loopy.i, ++ loopy.ptr) {...}  

Since C +11, you start different parts more beautifully Unless they are dependent on local variables:

 for  (struct {int i = 0; std :: string status;} loop; loop.stat us! = " Done "; ++ loop.i) {...}  

This is actually quite readable to actually use.


The problem with structured binding is set to address C ++ 17:

 for  (auto [i , Position] = {0, "" s}; condition! = "Done"; ++ i)  

However, the detailed feature set and syntax are still in Flux.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -