While loop only run once

I have a notebook which has a while loop wrapped into a function call.

The while loop runs intially but when updating values in the notebook it does not rerun making the notebook non-reactive.

This is caused by the condition of the while loop. I’m wondering it it’s possible to have a callback function in the sliders in order to clear the state?

solved this issue myself by making the state contained in the function itself and then returning the new state from the function

2 Likes

I looked at your initial notebook but got distracted before I could put together a solution, sorry :slight_smile: The problem is that you had a mutable variable, which trips up the dependency calculations in Observable. There are two ways to solve this: use the mutable keyword on those variables you’re affecting, or encapsulate the state, like you did. The latter is the better option, even if it takes a bit of getting used to (depending on what coding school of thought you’re coming from :).

Glad you figured it out, though! Modeling is a great use case for Observable.

2 Likes