Method

# UserCancelled

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to determine if the user has pressed Escape (on Windows or Linux) or Command-period (on macOS) or to cancel the execution of code.

## Usage

``` xojo
result = UserCancelled 
```

| Part   | Type                               | Description                                                                                                                                                                              |
|--------|------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| result | `Boolean</api/data_types/boolean>` | *result* is `True</api/language/true>` if the user has pressed Escape (on Windows or Linux) or Command-period (on macOS) or and `False</api/language/false>` if the user did not cancel. |

## Notes

The <span class="title-ref">UserCancelled</span> function will continue to return `True</api/language/true>` until the event handler that was executing when the user pressed Escape or Command-period is finished.

## Sample code

This example uses the <span class="title-ref">UserCancelled</span> function to exit a `For</api/language/loops/for...next>` loop if the user presses Command-period/Escape.

``` xojo
Const kMax = 10000000

For i As Integer = 0 To kMax
  ProgressBar1.Value = (i / kMax) * ProgressBar1.MaximumValue
  If UserCancelled Then
    Exit
  End If
Next
```

## Compatibility

|                       |                       |
|-----------------------|-----------------------|
| **Project Types**     | Console, Desktop, Web |
| **Operating Systems** | All                   |

<div class="seealso">

`Exit</api/language/loops/exit>`, `Do...Loop</api/language/loops/do...loop>`, `For...Next</api/language/loops/for...next>`, `While...Wend</api/language/loops/while...wend>` statements; `DesktopApplication</api/user_interface/desktop/desktopapplication>` class.

</div>
