digitalmars.D.learn - single loop copy in D
- psychoticRabbit (7/7) Mar 02 2018 trying to do this C code, in D, but getting error:
- Andrea Fontana (5/12) Mar 02 2018 You can't use this syntax inside a while/if/... to prevent
- Jonathan M Davis (6/13) Mar 02 2018 You can't use = in a while loop's condition like that in D, regardless o...
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (7/21) Mar 02 2018 This is of course only partly true.
- psychoticRabbit (2/8) Mar 02 2018 That's what I was after. Thanks!
trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: ------ while ((*dst++ = *src++)) {} ------
Mar 02 2018
On Friday, 2 March 2018 at 09:44:20 UTC, psychoticRabbit wrote:trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: ------ while ((*dst++ = *src++)) {} ------You can't use this syntax inside a while/if/... to prevent mistakes due to similarity between assignment syntax (=) and comparison syntax (==) Andrea
Mar 02 2018
On Friday, March 02, 2018 09:44:20 psychoticRabbit via Digitalmars-d-learn wrote:trying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: ------ while ((*dst++ = *src++)) {} ------You can't use = in a while loop's condition like that in D, regardless of what you do with parens. You'll need to refactor the code so that the assignment is done in the loop's body. - Jonathan M Davis
Mar 02 2018
On Friday, 2 March 2018 at 10:01:34 UTC, Jonathan M Davis wrote:On Friday, March 02, 2018 09:44:20 psychoticRabbit via Digitalmars-d-learn wrote:This is of course only partly true. while ((*dst++ = *src++) != 0) {} works just great, and also better shows what's actually being tested for in the loop. -- Simentrying to do this C code, in D, but getting error: "Error: assignment cannot be used as a condition, perhaps `==` was meant?" any help much appreciated: ------ while ((*dst++ = *src++)) {} ------You can't use = in a while loop's condition like that in D, regardless of what you do with parens. You'll need to refactor the code so that the assignment is done in the loop's body.
Mar 02 2018
On Friday, 2 March 2018 at 10:08:57 UTC, Simen Kjærås wrote:This is of course only partly true. while ((*dst++ = *src++) != 0) {} works just great, and also better shows what's actually being tested for in the loop. -- SimenThat's what I was after. Thanks!
Mar 02 2018