I'm writing a brainfuck interpreter, and the loops don't work, I don't know why. it's probably some dumb mistake. case "[": t("enter a loop") depth = 1 index = 0 if tape[pointer] == 0: t("skip a loop") #skip to the matching ] while depth != 0: t(f"depth: {depth}") index += 1 if code[i + index] == "]": depth -= 1 elif code[i + index] == "[": depth += 1 else: t("loop is verified") code_snippet = "" while depth != 0: t(f"depth: {depth}") index += 1 if code[i + index] == "]": depth -= 1 elif code[i + index] == "[": depth += 1 if depth != 0: t("found end") code_snippet = code_snippet + code[i + index] interpret(code_snippet) this is what I tried; the loops don't work. t() is just a debug function and interpret() is recursively interpreting brainfuck code, I've verified that the interpreter works. Continue reading...