September 13, 2004
In article <chvfet$nq$1@digitaldaemon.com>, clayasaurus says...
>
>Ah! Thank you! Yes that is exactly what is happening, I was trying to use add to generate the textures, but forget it adds one to the length *oops*
>
>Well I got it fixed now. Thanks alot.

No problem :-)

(Ignore the double post, misplaced a mouse click)

Nick


September 13, 2004
In article <ci2en1$avj$1@digitaldaemon.com>, clayasaurus says...
>
>Sha Chancellor wrote:
>> Why don't you use a foreach?
>
>What distinct advantages does foreach have over for loops? Is it just syntatical sugar?

Basically, yes.

>I looked at the dsource.org foreach tutorials and it seems you have to overload the opApply operator for classes?

Only if you want to do something like
class Foo ...
..
Foo f;
foreach(int i; f) {...}

Foo can be a custom container class, or something else. For example I have made a permutation class:

foreach(char[] a; Permute("abcd")) writefln(a);

which outputs abcd, bacd, bcad, and so on.

>I dunno the for loop just seems simpler and less confusing to me, and I don't see any clear advantages with using foreach. *enlighten me*

Then go ahead and use for loops. Foreach is just a somewhat cleaner way of iterating arrays, since you don't have to specify start value and array length explicitly. It also gives you a consistent way of iterating custom objects and arrays alike.

Nick


September 15, 2004
Sorry if this is a dumb question, but how you do something like this

#int findc(char []s,chat c){
# for(int x=0;x<s.length;x++){
#    if(s[x]==c)return x;
# }
#}

using foreach, not for?



In article <ci4pv1$313a$1@digitaldaemon.com>, Nick says...
>
>In article <ci2en1$avj$1@digitaldaemon.com>, clayasaurus says...
>>
>>Sha Chancellor wrote:
>>> Why don't you use a foreach?
>>
>>What distinct advantages does foreach have over for loops? Is it just syntatical sugar?
>
>Basically, yes.
>
>>I looked at the dsource.org foreach tutorials and it seems you have to overload the opApply operator for classes?
>
>Only if you want to do something like
>class Foo ...
>..
>Foo f;
>foreach(int i; f) {...}
>
>Foo can be a custom container class, or something else. For example I have made a permutation class:
>
>foreach(char[] a; Permute("abcd")) writefln(a);
>
>which outputs abcd, bacd, bcad, and so on.
>
>>I dunno the for loop just seems simpler and less confusing to me, and I don't see any clear advantages with using foreach. *enlighten me*
>
>Then go ahead and use for loops. Foreach is just a somewhat cleaner way of iterating arrays, since you don't have to specify start value and array length explicitly. It also gives you a consistent way of iterating custom objects and arrays alike.
>
>Nick
>
>


September 15, 2004
M wrote:

> Sorry if this is a dumb question, but how you do something like this 
> 
> #int findc(char []s,chat c){
> # for(int x=0;x<s.length;x++){
> #    if(s[x]==c)return x;
> # }
> #}
> 
> using foreach, not for?
> 
> 


#int findc(char[] s, char c)
#{
#  foreach(int x, char fc; s)
#    if(fc == c)
#      return x;
#}

-Deja
1 2
Next ›   Last »