# Tag Info

### How to pass variables by reference and by value

You asked for a general explanation instead of just focusing on specific application examples, so here it goes ... The concepts of "pass by reference" and "pass by value" that you ...
Accepted

### An efficient way to translate a triple for-loop from Matlab to Mathematica

Okay, let's focus on this snippet: ...
Accepted

### how to remove Null's from output?

Table[If[Mod[n!, n^(2 n)] == 0, n], {n, 1, 1000}] /. Null -> Sequence[] {1} ...

### How do I achive the function of Continue using Catch and Throw?

If you wrap the body of the loop with Catch, then any Throw will act as Continue: ...
Accepted

### Improve speed with a double for loop

Even in MATLAB, this would not be good programming style because successive concatenation is awfully slow. (And for is slow, too.) Better use ...
Accepted

### Implementing "do this, then return that" in function definitions

If you want, you could write some thing like this f[x_] := Module[{k = x}, Do[k = k^2 + 1, {i, 0, x - 1}]; k] A more natural form would be ...

### What is the most efficient way to define a Loop until function?

Here's a simpler version: SetAttributes[Until,HoldAll] Until[body_, test_] := While[body; !test]
Accepted

### An efficient way to evaluate this expression with deeply nested Do loops

UPDATE: After reposting the below function after modifications from the deleted post to make it work after OP question was changed, I determined a way to utilize ideas from the original deleted post's ...

### How to terminate a loop when the length of a list reaches a certain length?

If you introduce a length bound already, there is absolutely no reason for Append/AppendTo. Such a loop with ...
Accepted

### What is the most efficient way to define a Loop until function?

I tend to use While[True, body; If[condition, Break[]] ] but what you show is equally good. This is just an alternative. Try to avoid procedural loops in ...

### How to pass variables by reference and by value

You need: SetAttributes[myfunc, HoldAll] You then have: ...
Accepted

### Problem with Excel operation in NETLink way

In the Excel object model, the worksheet symbol Cells represents a property, not a method. In Visual Basic and other languages, many properties have a default ...
Accepted

### While loop in a function

In addition to the very good suggestions by Fraccalo, the issue here is that Mathematica refuses to overwrite arguments of functions (in general). So you have to introduce a local variable like this: ...

### Improve speed with a double for loop

(Subtract @@@ Subsets[Most@x, {2}])^2 + (Subtract @@@Subsets[Most@y, {2}])^2 will produce precisely the output of your OP with appropriate performance. Since your ...
Accepted

### How can I replace a set of Nested For Loops with a Functional Code Alternative?

Update: A faster alternative: ...

### Implementing Newton's Method?

The main reason is that x1 is not assigned a value before entering the for loop: ...

### Implementing Newton's Method?

Worth putting it out there that the For loop is not your friend. This does the same ...
Accepted

### how can i get the following figure using the for loop

Welcome to MMA SE! What the code above does is simply repeatedly overwrite the value of A. In each iteration of the loop, it evaluates ...
Accepted

### How to put a FOR loop in a WHILE loop

My answer is, "Don't". Create CAC. ...
Accepted

### Iterating FindRoot to solve a differential equation

As I noted in an earlier comment, the ODE to be solved can be rewritten as eq = y'[x] == Log[1 - Exp[-y[x]]] Then, ...

### Functional equivalent of a For loop referring to consecutive elements in a list

This duplicates the behavior of yours (no effect on zeroes at ends): ...
Accepted

### Mimic a procedural, recursive clustering algorithm for site percolation using functional programming

Built-in option This sidesteps most of your code, so it might not be what you are looking for, but I believe your goal can be achieved with Mathematica's built-in image processing capability, ...
Accepted

### Creating a multiline function with localized variables

You should write your function like so: myFunction[x_] := Module[{y}, y = x; y = y + 3; (y + 3)^3] Note the underscore in ...
Accepted

### Populating function inputs from lists

f@@(list1 ~Join~ list2) Or, more generally, use @@ to "open" the structure of List: <...
Accepted

### Evaluating number of iteration with a certain map with While

The problem with your code is that for some values of c, Abs[z] will never become larger than 2. You need to cap the number of ...

...

### Writing code to produce continued fractions

I think both your code and your Wolfram|Alpha query gave the wrong answer. Here is how I would write a function to generate a rational value from a list of continued fraction terms. ...

### How to terminate a loop when the length of a list reaches a certain length?

Try A={1,2,3,4}; While[Length[A] < 10, A = Append[A, 3.14]] Which gives ...