Re: Foreach loop behaviour and manipulation

2014-01-07 Thread H. S. Teoh
On Tue, Jan 07, 2014 at 09:38:34PM +, Binarydepth wrote: > > >or ... for(count=1;count>0 && count<100 || count>999 && > >count<1 || etc...; count++ ) > > That won't work. It's better separate foreach loops. Y'know, this code snippet really reminds me of why Jackson Structured Progra

Re: Foreach loop behaviour and manipulation

2014-01-07 Thread Binarydepth
or ... for(count=1;count>0 && count<100 || count>999 && count<1 || etc...; count++ ) That won't work. It's better separate foreach loops.

Re: Foreach loop behaviour and manipulation

2014-01-07 Thread Binarydepth
On Thursday, 28 November 2013 at 23:45:26 UTC, H. S. Teoh wrote: On Fri, Nov 29, 2013 at 12:36:18AM +0100, Binarydepth wrote: Hi guys I'm having some problems. Calculations are not working as expected and I get segmentation fault. I used the 2.059 version and it runs after compilation on compi

Re: Foreach loop behaviour and manipulation

2013-12-02 Thread Maxim Fomin
On Friday, 29 November 2013 at 00:41:16 UTC, bearophile wrote: H. S. Teoh: Modifying the loop variable of a foreach is, in general, a risky move. Right. In my opinion D programmers should learn that this is the preferred idiom of using foreach ranged loops: foreach (immutable i; 0 .. n) {}

Re: Foreach loop behaviour and manipulation

2013-12-02 Thread Binarydepth
foreach (immutable t; 1 .. 51) { int temp = (((t * 20) + 420) * 5) + 3; arr[t - 1] = temp - a; temp = (((t * 5) + 50) * 20) + 1013; arr[t] = temp - a; } Good work with the parenthesis. :)

Re: Foreach loop behaviour and manipulation

2013-12-02 Thread Binarydepth
On Friday, 29 November 2013 at 09:15:28 UTC, Joseph Rushton Wakeling wrote: On 29/11/13 00:36, Binarydepth wrote: I'm wondering in the case of manipulating the variable from the foreach loop, Do I have to reset that variable so the loop can work as intended ?(chronologically). I think that yo

Re: Foreach loop behaviour and manipulation

2013-11-29 Thread Joseph Rushton Wakeling
On 29/11/13 00:36, Binarydepth wrote: I'm wondering in the case of manipulating the variable from the foreach loop, Do I have to reset that variable so the loop can work as intended ?(chronologically). I think that you are approaching this problem in the wrong way. Instead of using a tempora

Re: Foreach loop behaviour and manipulation

2013-11-28 Thread bearophile
H. S. Teoh: Modifying the loop variable of a foreach is, in general, a risky move. Right. In my opinion D programmers should learn that this is the preferred idiom of using foreach ranged loops: foreach (immutable i; 0 .. n) {} If a D programmers really needs to modify the index inside the

Re: Foreach loop behaviour and manipulation

2013-11-28 Thread Binarydepth
On Thursday, 28 November 2013 at 23:45:26 UTC, H. S. Teoh wrote: On Fri, Nov 29, 2013 at 12:36:18AM +0100, Binarydepth wrote: Hi guys I'm having some problems. Calculations are not working as expected and I get segmentation fault. I used the 2.059 version and it runs after compilation on compi

Re: Foreach loop behaviour and manipulation

2013-11-28 Thread Binarydepth
I fixed a formatting problem on the code just now. And also a note is that the numbers are supposed to display a number depending on the initial value of the variable that the foreach loop is increasing and the users age. So if you were born in 1977 you input your birth year to the program an

Re: Foreach loop behaviour and manipulation

2013-11-28 Thread H. S. Teoh
On Fri, Nov 29, 2013 at 12:36:18AM +0100, Binarydepth wrote: > Hi guys I'm having some problems. Calculations are not working as > expected and I get segmentation fault. I used the 2.059 version and > it runs after compilation on compileonline.com [...] > foreach(t; 1..51) > { > temp=t; >

Foreach loop behaviour and manipulation

2013-11-28 Thread Binarydepth
Hi guys I'm having some problems. Calculations are not working as expected and I get segmentation fault. I used the 2.059 version and it runs after compilation on compileonline.com But I imagine is either a rookie mistake or a bug, what I'm curious about is the foreach loop. I'm wondering in