for loop

Zachary Lund admin at computerquip.com
Sun Jan 22 09:37:35 PST 2012


On 01/22/2012 11:08 AM, bearophile wrote:
> Max Klyga:
>
>> If you want to declare and initialize several variables in the for
>> loop, you can do it if they are of the same type:
>>
>> for (int x = 0, y = 0; ...; .++x, ++y) { ... }
>
> And if you need different types this sometimes is enough:
>
> void main() {
>      for (auto x = 0, y = 0.0; x<  10; x++, y++) {
>      }
> }
>
> Bye,
> bearophile

This is an ugly solution (and I'm not 100% sure it's valid D) but:

/+++++++++++++++++++++++++++++/
void main() {
	{
		short y = 0;
		int x = 0;

		for (; x < 10; ++x, ++y)
		{
		}
	}
}
/+++++++++++++++++++++++++++++/


More information about the Digitalmars-d-learn mailing list