C# Incrementing an variable till it reaches a certain amount?

Hi everyone, is it possible to increment a variable till it reaches a certain amount? I know this can be done with if statements but I’m wondering if it can be done with just the incremental operator. I"m guessing it would look something like this. ++somevar till 40;

No you need to use if or Mathf.Clamp. You can use the ternary operator too:

   i = i < 40 ? i+1 : i;