Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 7:46 AM, Dennis wrote: On Wednesday, 12 October 2022 at 10:09:31 UTC, Steven Schveighoffer wrote: I'm actually very surprised that just wrapping the statement in an == expression doesn't do the trick, what is the possible logic behind outlawing that? I looked into it, there are

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 9:17 AM, Rene Zwanenburg wrote: On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Am I missing something? Perhaps I am, but why not turn it into a numeric comparison, like: ``` while((i = 5) == 0) ``` Yes, that is the answer, that was eluding me. What

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Am I missing something? Perhaps I am, but why not turn it into a numeric comparison, like: ``` while((i = 5) == 0) ```

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread user1234 via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: ```d int x; while(!(x = 5)) { break; } ``` Error is: assignment cannot be used as a condition, perhaps `==` was meant? ... I think D should relax the restriction

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Dennis via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 10:09:31 UTC, Steven Schveighoffer wrote: I'm actually very surprised that just wrapping the statement in an == expression doesn't do the trick, what is the possible logic behind outlawing that? I looked into it, there are actually two different places where

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/12/22 5:24 AM, Dennis wrote: On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: I had the same issue, where the pattern was this: ```C void f() {     int err;     if (err = some_api_call()) {    

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Dennis via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: I had the same issue, where the pattern was this: ```C void f() { int err; if (err = some_api_call()) { printCode(err); return; } if

How to workaround assignment not allowed in a condition?

2022-10-11 Thread Steven Schveighoffer via Digitalmars-d-learn
Porting some C code to D This results in an error: ```d int x; while(!(x = 5)) { break; } ``` Error is: assignment cannot be used as a condition, perhaps `==` was meant? OK, fine, I'll use `==`: ```d int x; while(!(x = 5) == true) { break; } ``` Nope, same error. I tried reversing the