# nested loops

**URL:** <https://techcommunity.softwareag.com/t/nested-loops/185188>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [November 19, 2015, 5:48pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188 "2015-11-19T17:48:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_prasad2](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@krishna\_prasad2](https://techcommunity.softwareag.com/u/krishna_prasad2)\
**Post date:** [November 19, 2015, 5:48pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188/1 "2015-11-19T17:48:51Z")

</div>

I have a question. I have a piece of code where there are nested processing loops. say loop 3 is in loop 2 and loop2 is in loop1. I have a condition in loop 3 and if the condition is true code execute the rest of the process in loop 3 if the condition fails the control of the execution must come out of Loop1(which means the control comes out of loop 3 and loop2 and loop 1 at once).  
Is there any GOTO statements in Natural to achieve the above scenario. I am new to the natural and adabas.

Thank You and regards  
Krishna Prasad

---

<div class="post-metadata">

**Author:** ![Nikolay\_Kuhta](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@Nikolay\_Kuhta](https://techcommunity.softwareag.com/u/Nikolay_Kuhta)\
**Post date:** [November 19, 2015, 8:08pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188/2 "2015-11-19T20:08:46Z")

</div>

Hi Krishna Prasad,  
I think you would need ESCAPE BOTTOM (there`s also ESCAPE TOP) statement; unfortunately (or rather fortunately), there`s no GOTO in NATURAL nowadays.  
Perhaps, the following code might help you (just try it out to understand ESCAPE statement):

DEFINE DATA LOCAL  
1 #I (I4)  
1 #J (I4)  
1 #K (I4)  
END-DEFINE  
LOOP-ONE-MAIN.  
FOR #I = 1 TO 100  
LOOP-SEC.  
FOR #J=1 TO 50  
LOOP-THIRD.  
FOR #K = 1 TO 10  
DISPLAY ‘=’ #K  
IF #K = 5  
ESCAPE BOTTOM (LOOP-ONE-MAIN.)  
END-IF  
END-FOR  
END-FOR  
END-FOR  
WRITE ‘=’ #I ‘=’ #J ‘=’ #K  
END

Best regards and good luck.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [November 20, 2015, 1:57pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188/3 "2015-11-20T13:57:26Z")

</div>

A few things to add to Nikolay’s response, which should solve your immediate problem.

ESCAPE is a very powerful statement. You should look at the differences between ESCAPE TOP and BOTTOM. While you can ESCAPE BOTTOM with a line reference or a symbolic reference, you cannot do this with ESCAPE TOP. You can only do this to an innermost loop.

Also, if you are working with data loops (e.g. READ, FIND) and have AT BREAK or AT END clauses, be careful about the difference between ESCAPE BOTTOM and ESCAPE BOTTOM IMMEDIATE. Also, look at the relatively new option REPOSITION.

Read up on ESCAPE ROUTINE and ESCAPE MODULE.

---

<div class="post-metadata">

**Author:** ![krishna\_prasad2](https://avatars.discourse-cdn.com/v4/letter/k/22d042/32.png) [@krishna\_prasad2](https://techcommunity.softwareag.com/u/krishna_prasad2)\
**Post date:** [November 20, 2015, 7:57pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188/4 "2015-11-20T19:57:51Z")

</div>

Thanks Nikolay and Steve for your response. The information really helps.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:34pm UTC](https://techcommunity.softwareag.com/t/nested-loops/185188/5 "2021-04-02T15:34:43Z")

</div>


