Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Indefinite loop that breaks Codea.

AnatolyAnatoly Mod
in Bugs Posts: 870
    for a in function()
        return 2
    end do
        print(2)
    end

Codea gets stuck after activation.

Tagged:

Comments

  • Posts: 1,351

    @Anatoly - yup, same on my machine but I can't really understand what you are trying to achieve with that code?

  • dave1707dave1707 Mod
    edited November 9 Posts: 7,836

    Just about any infinite loop will crash Codea. The one below will crash too.

    One thing I noticed when I was playing with this, any code changes weren’t saved. But that was expected because I know that if Codea crashes, it doesn’t save code changes.

    @Simeon One thing I noticed running @Anatoly code above, even if I did the Save and Run, the code wasn’t saved. It reverted back to the original code.

    PS. Even my code wasn’t saved when I did the Save and Run. I wonder if any kind of a problem in setup might be causing the loss of code.

    function setup()
        while true do
            print("a")
        end
    end
    
  • Posts: 443

    That's an interesting infinite loop. The anonymous function is defining an iterator which can be repeatedly called. The classic iterator is ipairs, but it's possible to define your own. In this code, you're defining an iterator which returns the value 2 whenever it is called.

    The for ... in ... syntax will keep calling the iterator until it gets a nil. Since it always returns 2, it will never end and the for loop will keep going round.

    As I said - an interesting infinite loop!

  • AnatolyAnatoly Mod
    edited November 9 Posts: 870

    @dave1707 nice to notice that if you remove the print function,you can still exit the code. It’s hard, but possible.

    I believe it’s because printing is such a slow function. Not sure however why Save & Run won’t work.

    @LoopSpace was trying to create my own interators, just was testing out some stuff.

    It’s suggested for anyone who uses the while loop:
    - Before the indefinite loop create n which equals zero.
    - Inside the loop (1) increase n by one and
    - (2) check if n is more than 10000 (or less), after which break the loop.

  • AnatolyAnatoly Mod
    Posts: 870

    Sadly my internet lagged out and the post was trashed. Here were two points:

    • Recording is Brocken
    • Opening alerts in a for loop is bad. (Earlier you could escape it)
Sign In or Register to comment.