30

Is there a command to step out of cycles (say, for or while) while debugging on ipdb without having to use breakpoints out of them?

I use the until command to step out of list comprehensions, but don't know how could I do a similar thing, if possible, of entire loop blocks.

4 Answers 4

29

I believe this is the intent of the until command. It's like a next except that when a jump occurs to a previous line number for the loop, it will continue until exiting the loop.

unt(il)
Continue execution until the line with a number greater than the current
one is reached or until the current frame returns

In general, to "step out" of the current function, use return.

r(eturn)
Continue execution until the current function returns.
3
  • nope, until steps out of list comprehensions for example. It continues execution UNTIL reching a different line number as the current one, just that. If inside some code block (for, while, anything else), there's no way but with breakpoints, as far as I have researched Aug 1, 2015 at 20:14
  • @Javier Navoa What you described for until is the behavior of next. I believe he is right: until is just like next except that it always goes down. In that way until can effectively be used to go out of loops, but it can take several times (the number of lines remaining in the loop).
    – Jean Paul
    Oct 4, 2018 at 13:33
  • The trap is that the debugger understands list comprehensions as several lines, but it is the same for next and until.
    – Jean Paul
    Oct 4, 2018 at 14:32
24

You can use j <line number> (jump) to go to another line. for example, j 28 to go to line 28.

1
  • 6
    as pointed out by jimifiti, jump skips the jumped lines, so it is not similar to until
    – Jean Paul
    Feb 18, 2019 at 10:52
15

This could sound obvious: jump makes you jump. This means that you don't execute the lines you jump: you should use this to skip code that you don’t want to run.

You probably need tbreak (Temporary breakpoint, which is removed automatically when it is first hit. The arguments are the same as break) as I did when I found this page.

1

If you are willing to use another debugger, trepan, has more ways you can step. It is more gdb-like. So you can give a count of how many times you want to step. Or you can give a line number in a continue debugger command which in essence sets a temporary breakpoint at the line and then issues "continue". Other things that change stepping are "set different". See also the even suffixes you can put on step.

Note that like ipdb, there is syntax highlighting of the source text.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.