How do you make a range in Rust?

As of 1.0, for loops work with values of types with the Iterator trait. The book describes this technique in chapter 3.5 and chapter 13.2. If you are interested in how for loops operate, see the described syntactic sugar in Module std::iter. Example: fn main() { let strs = [“red”, “green”, “blue”]; for sptr in … Read more

What’s the difference between iterating over a file with foreach or while in Perl?

For most purposes, you probably won’t notice a difference. However, foreach reads each line into a list (not an array) before going through it line by line, whereas while reads one line at a time. As foreach will use more memory and require processing time upfront, it is generally recommended to use while to iterate … Read more

ZSH for loop array variable issue

It’s actually much simpler than that: lw=(‘plugin1’ ‘plugin2’ ‘plugin3’) for i in $lw; do . ~/Library/Rogall/plugins/$i/lw.prg end done In summary: Assign to foo, not $foo (the shell would try to expand $foo and assign to whatever it expands to; typically not useful) Use the loop variable directly; it contains the array value rather than the … Read more

Batch file FOR /f tokens

for /f “tokens=* delims= ” %%f in (myfile) do This reads a file line-by-line, removing leading spaces (thanks, jeb). set line=%%f sets then the line variable to the line just read and call :procesToken calls a subroutine that does something with the line :processToken is the start of the subroutine mentioned above. for /f “tokens=1* … Read more

push() a two-dimensional array

You have some errors in your code: Use myArray[i].push( 0 ); to add a new column. Your code (myArray[i][j].push(0);) would work in a 3-dimensional array as it tries to add another element to an array at position [i][j]. You only expand (col-d)-many columns in all rows, even in those, which haven’t been initialized yet and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)