I'm learning how to use bash to write my first script for college, but I'm having trouble with nested statements/loops/functions.

I'm trying to write an if statement where if a variable value is true, it breaks/returns out of that if statement, then also breaks out of a containing while loop, that is also part of a function, that I want to end (when the if statement's variable is true).

I've tried return N, break N, and exit (I now know this just ends the script.)
Here is an example of how I have attempted to set my script up.

```bash
#!/bin/bash

function1()
{
    while read -p "Enter a value: " input
    do
        if [ $input="X" ]
        then
            return 2
        fi
        # Rest of while statement
    done
    # End of while loop.
}
# End of function.

function1
# Call function1.
# Rest of script

```

Can anyone shed any knowledge on how this should work please?
(I do apologise for the appalling formatting of this question, I'm new to the site and haven't really sat down and spent time to learn how it works, sorry.)