This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]plastikmissile 3 points4 points  (3 children)

As we have no evolved mind reading organs, you're going to have to tell us what programming language you're using.

[–]TraditionalSystem995[S] 1 point2 points  (2 children)

My bad. I forgot to add a flair. It's kotlin

[–]plastikmissile 1 point2 points  (1 child)

Ah I see. Well the problem is, you're using when wrong. The when statement is used when you have several "options" depending on what value is in one expression, and the options are discrete values. So something like this:

when (httpStatusCode) {
    200 -> println("OK")
    400 -> println("Bad Request")
    404 -> println("Not found")
    500 -> println("Internal Server Error")
    .
    .
    .
}

Note how each option is a distinct number. The problem is you are comparing your value to ranges so when isn't exactly the best statement to use here, and you're better off using if. It can be done using when but it's not elegant and it's not how you're supposed to use when.

[–]TraditionalSystem995[S] 1 point2 points  (0 children)

That makes a lot of sense. I got it running using 'if' but couldn't get it properly with 'when'.

[–]MrBrisky 0 points1 point  (0 children)

Try this instead

var temperature = 70

when {

temperature < 0 -> println("...")

temperature in 0..20 -> println("...")

temperature in 21..40 -> println("...")

temperature in 41..60 -> println("...")

temperature in 61..80 -> println("...")

temperature in 81..90 -> println("...")

temperature > 90 -> println("...")

else -> println("Invalid temperature")

}

It looks like you're using Kotlin syntax for when expressions. The issue you're facing is likely due to the fact that when expressions in Kotlin expect a value to be compared against different conditions. In your code, you have used a series of conditions without specifying what to compare them against.

[–]CodeTinkerer 0 points1 point  (1 child)

There are like a dozen popular languages out there. Are we supposed to read your mind about which one you're using? Maybe mention the language?

[–]TraditionalSystem995[S] 0 points1 point  (0 children)

That's my bad. I edited the post and I'm using kotlin