Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Continuing Execution

unt stands for until and will continue execution up until a specified line. If no line number is specified, then it behaves similarly to the n command, because execution will continue just one line.

The only difference is that this is not logically executed, and so the unt command will iterate through entire loops automatically, instead of just moving forward one iteration. If you do supply a line number, unt will act like the c command, except you’re telling it where to stop.

00:00 So far, we’ve looked at stepping through code with n and s, and using breakpoints with b and c. There’s also a related command called unt.

00:15 This is short for until. This command can behave in one of two ways, depending on if we give it a line number or not. If we supply a line number, execution will continue until a line with a number greater or equal to that is reached. This is just like using the c command to continue, except we’re actually telling it where to stop.

00:41 If we don’t supply a line number, execution will continue until the line with a number greater than or equal to the current one is reached.

00:51 This is just like the n command because it will only move forward one line. The only difference is n will stop at the next logically executed line, whereas unt will stop only when a line with a number greater than the current one is reached. To better understand this, let’s look at an example using a simple for loop.

01:17 I’ve got a file here called example4unt.py, which contains this all-too-familiar get_path() function we’ve been using. Except right here, I have a for loop that will loop through each character in the tail string, setting char equal to that variable on each iteration.

01:40 This means that after the last iteration, char should be equal to the last character in the tail string. I’m going to run this with ./example4unt.py, and execution will stop at the breakpoint. Just to make this clear, I’ll run ll, or longlist, to see the contents of this function, with an arrow (->) pointing to where we’ve stopped. To move on to the next line, I’ll say unt, and because I’m supplying no line number, it will act just like the n command for next. We’re now stopped at the beginning of our for loop.

02:22 Now I’ll hit Enter, which will implicitly run unt again. And I’ll do that once more, just so we’re out of the loop. Here, if I had entered n for next, it would have iterated through the loop just once, and I’d have to do that over and over again until we’ve iterated through every character.

02:45 But the unt command will take us to the next line no matter what, and so it automatically runs through the entire loop for us. And just to show that it worked, I’ll type p char,tail,

03:01 and you see that char is set to the last character in tail. It definitely iterated all the way through the string. Pretty cool.

Become a Member to join the conversation.