1

When I run a script with PDB, I find that I have to put for loops into one line to run correctly. When I try to nest for loops as shown below, I get a SyntaxError. How can I run nested for loops??

(pdb) for input in range(20): print input*2
0
2
4
...
36
38

(pdb) for input in range(20): for output in range(10): print input*2
*** SyntaxError: invalid syntax(<stdin>, line 1)
kylieCatt
  • 10,672
  • 5
  • 43
  • 51
user278016
  • 821
  • 1
  • 7
  • 6
  • 2
    this may help you http://stackoverflow.com/questions/5967241/how-to-execute-multi-line-statements-within-pythons-own-debugger-pdb – Mauro Baraldi Aug 06 '14 at 21:39

1 Answers1

2

This does not have to do with pdb, but is just python (this fails in the normal python repl).

The grammar for a for statement is defined as:

for_stmt ::=  "for" target_list "in" expression_list ":" suite
              ["else" ":" suite]

where suite is either a list of simple statements or a newline and a list of statements. the for statment is a compound statement so it cannot be inlined like that.

Joe Jevnik
  • 81
  • 1
  • 1