# Escape top and bottom

**URL:** <https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [September 25, 2006, 8:27am UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496 "2006-09-25T08:27:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rich](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rich](https://techcommunity.softwareag.com/u/Rich)\
**Post date:** [September 25, 2006, 8:27am UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/1 "2006-09-25T08:27:38Z")

</div>

Hi,

Could anyone please explain me escape top and bottom with clear example.  
I know its in documentation but still explanation with example would be very helpful for me. Thankyou.

---

<div class="post-metadata">

**Author:** ![Weihnachtsbar](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/weihnachtsbar/32/146_2.png) [@Weihnachtsbar](https://techcommunity.softwareag.com/u/Weihnachtsbar)\
**Post date:** [September 25, 2006, 1:17pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/2 "2006-09-25T13:17:31Z")

</div>

```auto
DEFINE DATA LOCAL
1 COUNTER (I4)
1 BUTTON (A1)
END-DEFINE
*
FOR COUNTER = 1 TO 10
  IF COUNTER = 5
    PRINT 'Continue loop at the top...'
    ESCAPE TOP
  END-IF
  PRINT 'your counter is now:' COUNTER
  IF COUNTER = 8
    BUTTON := "N"
    INPUT 'Do you want to stop? (Y/N)' BUTTON (AD=MT)
    IF BUTTON = "Y"
      PRINT 'Ok - I stop it.'
      ESCAPE BOTTOM
    END-IF
  END-IF
END-FOR
*
PRINT 'It"s all over. Counter is now:' COUNTER
END
```

1. Does this help?

---

<div class="post-metadata">

**Author:** ![Rich](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rich](https://techcommunity.softwareag.com/u/Rich)\
**Post date:** [September 25, 2006, 2:12pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/3 "2006-09-25T14:12:38Z")

</div>

Thankyou for this good example.

---

<div class="post-metadata">

**Author:** ![Rich](https://avatars.discourse-cdn.com/v4/letter/r/35a633/32.png) [@Rich](https://techcommunity.softwareag.com/u/Rich)\
**Post date:** [September 25, 2006, 2:13pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/4 "2006-09-25T14:13:35Z")

</div>

Thankyou for this good example.

---

<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:** [September 25, 2006, 5:19pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/5 "2006-09-25T17:19:53Z")

</div>

ESCAPE BOTTOM IMMEDIATE is like a GO TO the statement after the end of a loop. By contrast, ESCAPE BOTTOM, all by itself (no IMMEDIATE) is not quite the same (except for REPEAT and FOR loops). With READ and FIND loops, ESCAPE BOTTOM first “finishes up” a loop before leaving the loop.

“Finishing up” a loop includes doing AT END OF DATA clauses, AT BREAK clauses, etc.

ESCAPE TOP is something of a misnomer; it does not “escape” a loop at all; it merely ends an iteration of the loop. I have met many programmers who thought it transferred control to the statement before a loop; not true. Functionally, ESCAPE TOP is basically identical to ACCEPT/REJECT statements.

steve

---

<div class="post-metadata">

**Author:** ![Eric\_Schindler](https://avatars.discourse-cdn.com/v4/letter/e/bbe5ce/32.png) [@Eric\_Schindler](https://techcommunity.softwareag.com/u/Eric_Schindler)\
**Post date:** [September 25, 2006, 6:12pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/6 "2006-09-25T18:12:49Z")

</div>

… sorry wrong posting …

---

<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, 2:40pm UTC](https://techcommunity.softwareag.com/t/escape-top-and-bottom/61496/7 "2021-04-02T14:40:52Z")

</div>


