Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: Re: Loops (was Re: do { quit; } else { }) Date: Tue, 22 Apr 2025 02:21:32 +0100 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 22 Apr 2025 03:21:32 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d044c27b80dbbae3d03ebae8688adc0f"; logging-data="3587799"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/6qP5zoKfxJYrsvRAxb3IX" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:ZmUTgox92MVX7LGGQjDvmmeVcwc= In-Reply-To: Content-Language: en-GB Bytes: 2896 On 21/04/2025 22:06, Waldek Hebisch wrote: > bart wrote: >> You have to analyse it first. The kind of loop this expresses is: >> >> p = startvalue() >> >> while (p) { >> >> p = nextvalue() >> } >> >> Notice how I chose to express it: it reflects how I would describe it in >> English: >> >> * Set P to Start Value >> * While P isn't Null: >> * Execute the body >> * Set P to Next Value >> >> So, how would /you/ describe it in English? (Or in any language if like, >> as the ordering is more important.) > > I would describe original sqlite3.c loop as "iteration over elements > of hash table". That assumes that Sqlite folks choose sensible > names. This is higher level view than you apparently have. You're guessing based on the identifiers chosen. But that lump of code has this shape: for(A; B; C) which is equivalent to: A; while (B) { body; C} However, you can see that A and C are assignments to the same variable, so you can reasonably refine to what I wrote above. But perhaps the English should have been 'While P is True' to avoid the assumption it is a pointer. You can't go beyond that however /from the shape of the code/. Remember, C-for is 'flexible'. That means it can literally be anything, but the general pattern of any such loop can be expressed with 'while'.