Domanda

I have a handful of if statements in ASP and one of them looks like this:

If i Mod 120 = 0 Or i Mod 124 = 0 Or i Mod 128 = 0 Or i Mod 132 = 0 Or i Mod 136 = 0 Or i Mod 140 = 0 Or i Mod 144 = 0 Or i Mod 148 = 0 Or i Mod 152 = 0 Or i Mod 156 = 0 Or i Mod 160 = 0 Or i Mod 164 = 0 Or i Mod 168 = 0 Or i Mod 172 = 0 Or i Mod 176 = 0 Or i Mod 180 = 0 Then

Basically it uses Mod from 120 to 180 incrementing by four. There are no exceptions in it. I'm somewhat new to this and can't figure out a more streamlined way to write this code. I have other if statements like this and figure it will make the code more readable and cleaner if I can find an easier way to write this out.

Thanks for your help!

È stato utile?

Soluzione

Use a For statement block to loop through:

For X = 120 to 180 Step 4
  If I Mod X = 0 Then
    'Do stuff
  End If
Next
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top