21

This is not a duplicate of How to come out of while loop during debugging. See the comment on this answer https://stackoverflow.com/a/8107702/1391924 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.

Community
  • 1
  • 1
Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68
  • Do you want to _skip_ them? Or just not run through the whole loop step by step? – Behe Dec 10 '13 at 10:14
  • 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. – Chandrayya G K Dec 10 '13 at 10:31
  • 1
    [Possible Duplicate](http://stackoverflow.com/questions/8106681/how-to-come-out-of-while-loop-during-debugging) – Prateek Dec 24 '13 at 06:40
  • Logged a bug against **JDT** [here](https://bugs.eclipse.org/bugs/show_bug.cgi?id=424887). Please vote up and request this feature in next **JDT** release. – Chandrayya G K Jan 04 '14 at 09:21
  • @ChandrayyaGK They don't seem to implement this in the next JDT.. The best option you have is using "Run to line". – Maroun Jan 21 '14 at 08:17
  • 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. – Christopher Barber May 31 '14 at 00:07
  • 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. – MasterJoe Sep 05 '18 at 22:01
  • Does this answer your question? [How to come out of while loop during debugging](https://stackoverflow.com/questions/8106681/how-to-come-out-of-while-loop-during-debugging) – paradocslover Jun 23 '21 at 01:35

2 Answers2

76

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

enter image description here

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • 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. – Chandrayya G K Dec 10 '13 at 10:16
  • 3
    @ChandrayyaGK If you have a big loop that's hard to find the line under it, that's a sign of a bad design. – Maroun Dec 10 '13 at 10:18
  • 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. – Chandrayya G K Dec 30 '13 at 05:57
  • @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. – Maroun Dec 30 '13 at 05:59
  • @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 :) – Maroun Dec 31 '13 at 13:43
  • 1
    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. – Christopher Barber May 31 '14 at 00:10
  • @ChristopherBarber That depends on whether you're reading the question in the title or in the post. – shmosel May 04 '17 at 03:11
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).

Maroun
  • 94,125
  • 30
  • 188
  • 241
Konstantin Yovkov
  • 62,134
  • 8
  • 100
  • 147