# Running "break 2" command from parameter for function



## setevoy (Oct 30, 2013)

Hello, people.

I have a "simple" script. In this script there is 
	
	



```
loop (cycle?) > function1 > if[...] > function2 > loop2
```

function2 has a second loop inside it:


```
function2 ()
    {
    while ... do
    ...
    done
    }
```

To end this sequence - function2 uses $param4 with break 2 command given in variable:


```
while function1; do
    ...
    function2 "$param1" "$param2" "$param3" "$param4
    ...
    done
```

And:


```
...
    param4="break 2"
    ...
```

Is it a good idea to use such a scheme? Is there any possible risk or something else "negative"?


----------



## wblock@ (Oct 30, 2013)

In general, the need to use less-than-simple loop breaking mechanisms means that the loops should be reorganized.



> Is it a good idea to use such a scheme? Is there any possible risk or something else "negative"?



It is difficult to follow or debug.  Possibly that's because the names of the functions and variables are not descriptive.  Why not have the inner loop test the condition internally so it can exit by itself?


----------

