How to skip loops while debugging Java code?
Asked Answered
B

2

21

This is not a duplicate of How to come out of while loop during debugging. See the comment on this answer https://mcmap.net/q/658530/-how-to-come-out-of-while-loop-during-debugging by the author of this question.

While debugging, we can use short-cut keys like F8 to resume, F7 to step return, F5 to step into, F6 to step over.

Is there any short-cut key to skip loops (for,while and do-while) while debugging Java code?

In the picture shown below

enter image description here Currently debug cursor is at line no 57. Is there any short cut key when pressed it debug cursor should come out of innermost loop (for,while or do-while. Here while loop) and pause at next executable statement (i.e excluding comments. Here line no 64). And when again pressed this key it should come to line number 66.

Edit:

Not got any satisfied answer. Raised a bug here. Please vote up and request this feature in next JDT release.

Burress answered 10/12, 2013 at 10:7 Comment(8)
Do you want to skip them? Or just not run through the whole loop step by step?Elisabeth
I don't want to press F6 again and again. I want to execute all statement inside loop and stop/pause at the statement after the loop.Burress
Possible DuplicateAgonized
Logged a bug against JDT here. Please vote up and request this feature in next JDT release.Burress
@ChandrayyaGK They don't seem to implement this in the next JDT.. The best option you have is using "Run to line".Southeasterly
I have not seen any other debugger that has a shortcut for jumping over loops. I really wouldn't hold your breath on something like that showing up in Eclipse unless you implement it yourself.Parlous
Side note - For Intellij Idea (Community edition 2018), place your cursor on any executable line of code which is after the for loop. Then, click the "run to cursor" button in the debugger. This will skip the for loop.Mukund
Does this answer your question? How to come out of while loop during debuggingAnatollo
S
76

Select the line that's out of the loop and press ctrl + r (Run to line):

enter image description here

Southeasterly answered 10/12, 2013 at 10:8 Comment(7)
Yes, I am aware of Ctrl + r short cut, but if the loop is big one I need to scroll to end of the loop and place cursor after that. I am looking some what similar to F7 short cut key. When we press F7 it places the debug cursor to the next statement after the method call.Burress
@ChandrayyaGK If you have a big loop that's hard to find the line under it, that's a sign of a bad design.Southeasterly
Yes I understand, but while working on my laptop the screen size will be less and get very less space for my editor. Also in case of embedded loops it's difficult to judge the end and start of the loops. I need to scroll back and forth to come to the end or start of each loop. Again I know the short cuts to go to matching brackets or scope selection but I have to scroll back or forth to go to start or end of the loop.Burress
@ChandrayyaGK I understand that. I looked on all the forums of Eclipse and couldn't find anything better that you can do. I afraid this is the closest thing you can do to "skip" loops while debugging. I'll keep searching and will update if I find something better.Southeasterly
@ChandrayyaGK I looked everywhere.. Doesn't look like there's an option for that. My suggestion is the best thing you can do.. At least nowadays :)Southeasterly
This is the correct answer. The poster may wish for an even easier alternative, but it doesn't exist. Refusing to pick this in the dim hope that someone will implement this feature someday isn't accomplishing anything.Parlous
@ChristopherBarber That depends on whether you're reading the question in the title or in the post.Lane
U
12

You can add a breakpoint after the loop and click F8 (resume). The debugger will stop on the next found breakpoint, e.g. you will have skipped the loop(s).

Ursula answered 10/12, 2013 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.