for-in loop |
Top Previous Next |
What is translated > Statements > for loop's > for-in loop
for-in loops are a special kind of Delphi for-loops which have the syntax:
var a : typename; begin for a in B do DoSomething(a);
where 'a' may be a character in a string 'B' or 'a' may be an element of an array 'B' or 'a' may be a member of a set 'B'. These cases mostly are translated to a C++11 range-based for loop:
typename a;
for (typename element_0 : B) { a = element_0; DoSomething(a); }
For C++Builder, in the special case, that 'B' is an open array, a cast is necessary. That may for example look like:
void __fastcall ArrayOfConstLoop(const T* B, int B_maxidx) { T a;
for(auto element_0 : *(T(*)[B_maxidx])B) { a = element_0; DoSomething(a); } }
The necessary iterators for sets and open arrays are defined in d2c_systypes.h.
For container types that implement a GetEnumerator() method the for loop looks like:
while(B->GetEnumerator()->MoveNext()) { T a = B->GetEnumerator()->Current DoSomething(a); }
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |