if integer is greater than x but less than y (Swift)

William Larson

I was wondering if there is any smooth way of checking the value of an integer in a range in swift.

I have an integer that can be any number between 0 and 1000

I want to write an if statement for "if the integer is between 300 and 700 - do this and if its any other number - do something else"

I could write:

if integer > 300 {
    if integer < 700 {
      //do something else1
    }
    //do something
} else {
    // do something else2

}

But I want to minimize the amount of code to write since "do something else1" and "do something else2" are supposed to be the same

It doesn't seem that you can write :

if 300 < integer < 700 {

} else {

}

I tried using

if integer == 300..<700 {
}

but that didn't work either. Anybody got a suggestion?

CrApHeR

Did you try this?

if integer > 300 && integer < 700 {
    // do something
} else {
    // do something else               
}

Hope this helps

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

why string is greater or less than the integer?

From Dev

How to find elements whose sibling index is less than x and greater than y

From Dev

Greater than or Less than equal to

From Dev

if greater than or less than and zero

From Dev

PHP If X greater than Y by more than Z

From Dev

If value is greater than, less than and becomes greater than again

From Dev

If value is greater than, less than and becomes greater than again

From Dev

Python Less/Greater than issue

From Dev

greater than and less than equals to in sql?

From Dev

Creating a greater than but less than function in XML

From Dev

Strange Greater than or Less than Results

From Dev

Greater than, Less than string Lua (Lapis)

From Dev

Using '/' as greater than less than in Python?

From Dev

Javascript diamond? (Less than followed by greater than)

From Dev

Is there a greater than but less than function in python?

From Dev

Greater than and less than symbol in regular expressions

From Dev

AppleScript less than number or greater than number

From Dev

Regex that detects greater than ">" and less than "<" in a string

From Dev

SQL Server - Dates, Greater than and Less than

From Dev

Returning greater than and less than values in pandas

From Dev

Greater than and Less than Value SSRS 2008

From Dev

greater than and less than equals to in sql?

From Dev

Greater than and less than symbol in regular expressions

From Dev

Strange Greater than or Less than Results

From Dev

Python greater than and less than operands not working?

From Dev

Use R switch for less than or greater than?

From Dev

.NET Greater than/less than not working

From Dev

implementing greater than / less than operator

From Dev

Not Greater Than Operator in Swift !>

Related Related

  1. 1

    why string is greater or less than the integer?

  2. 2

    How to find elements whose sibling index is less than x and greater than y

  3. 3

    Greater than or Less than equal to

  4. 4

    if greater than or less than and zero

  5. 5

    PHP If X greater than Y by more than Z

  6. 6

    If value is greater than, less than and becomes greater than again

  7. 7

    If value is greater than, less than and becomes greater than again

  8. 8

    Python Less/Greater than issue

  9. 9

    greater than and less than equals to in sql?

  10. 10

    Creating a greater than but less than function in XML

  11. 11

    Strange Greater than or Less than Results

  12. 12

    Greater than, Less than string Lua (Lapis)

  13. 13

    Using '/' as greater than less than in Python?

  14. 14

    Javascript diamond? (Less than followed by greater than)

  15. 15

    Is there a greater than but less than function in python?

  16. 16

    Greater than and less than symbol in regular expressions

  17. 17

    AppleScript less than number or greater than number

  18. 18

    Regex that detects greater than ">" and less than "<" in a string

  19. 19

    SQL Server - Dates, Greater than and Less than

  20. 20

    Returning greater than and less than values in pandas

  21. 21

    Greater than and Less than Value SSRS 2008

  22. 22

    greater than and less than equals to in sql?

  23. 23

    Greater than and less than symbol in regular expressions

  24. 24

    Strange Greater than or Less than Results

  25. 25

    Python greater than and less than operands not working?

  26. 26

    Use R switch for less than or greater than?

  27. 27

    .NET Greater than/less than not working

  28. 28

    implementing greater than / less than operator

  29. 29

    Not Greater Than Operator in Swift !>

HotTag

Archive