Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,050 of 33,346    |
|    Ivan Godard to Pete Becker    |
|    Re: Why does range based for loop requir    |
|    25 Mar 12 21:43:28    |
   
   From: igodard@pacbell.net   
      
   On 3/24/2012 4:35 AM, Pete Becker wrote:   
   > On 2012-03-24 05:31:44 +0000, Frank Birbacher said:   
   >   
   >>   
   >> // not allowed in C++11, but I want it to work:   
   >> int i;   
   >> for(i : vec) {...}   
   >>   
   >   
   > What should the value of i be after the loop? More generally, what do   
   > you want to be able to do with i after this loop?   
   >   
   The language Mary, an Algol68 derivative, had value-yielding loops.   
    do i: A1, j: A2 in   
    if (i = j) then i leave; fi;   
    out   
    0   
    od =: found;   
   The loop is bounded by "do"-"od". "leave" carries a value to the od, in   
   effect a "return" from the loop. If the loop ends without leaving then   
   the code between "out" and "od" is the value. The code between do and in   
   create the iteration variables; you can have more than one, and they   
   iterate in step. A1 and A2 are the streams to iterate over, probably   
   arrays in this case. The value yielded by the loop is assigned ("=:") to   
   "found"; Mary had strict left-to-right evaluation, including   
   assignments. Scoping is do{ in { } out { } } od, and all scopes are   
   serial clauses (statement lists) which return the value of the last   
   expression in the clause.   
      
   Equivalent C would be:   
    int t = 0;   
    int m = sizeof(A1) > sizeof(A2) ? sizeof(A1) : sizeof(a2);   
    for (int x = 0; x < m; ++x)   
    if (A1[x] == A2[x]) {   
    t = A1[x];   
    break;   
    }   
    found = t;   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca