IBM Support

GatewayScript debugger might not stop at every iteration of a for-in loop

Troubleshooting


Problem

In some cases, the GatewayScript debugger does not stop at every iteration of a for-in loop.

Environment

When you step through code with the next command, the debugger does not stop at every iteration of a for-in loop. The debugger stops at each line the first time through the loop, but not successive times. Instead, after the first iteration, the debugger passes out of the loop and stops at the next execution statement.

For example, the next command specifies that the debugger stops at the sum operation at line 6 for each iteration. Instead, the debugger stops at line 6 only the first time through the for-in loop.

   1: debugger;
   2: var sum = 0;
   3: var arr = [1, 2, 3, 4];
   4:
   5: for (var a in arr) {
   6: sum = sum + arr[a];
   7: }

Resolving The Problem

You can work around this issue with one of the following code changes:

  • Add a breakpoint in the for-in loop
  • Add another statement in the for-in loop

For example, you might add a breakpoint at line 6 or add a console.log() statement in the loop. Either one of these solutions forces the debugger to step through all statements in the for-in loop as expected.

   1: debugger;
   2: var sum = 0;
   3: var arr = [1, 2, 3, 4];
   4:
   5: for (var a in arr) {
** 6: sum = sum + arr[a];
   7: console.log(a);
   8: }

The debugger behavior does not affect the correctness of the results.

[{"Product":{"code":"SS9H2Y","label":"IBM DataPower Gateway"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF009","label":"Firmware"}],"Version":"7.0.0;7.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21693166