0

I have a loop from 1 to 20

I want to go through the loop only from 6 to 14

    For i As Integer = 0 To 19
        If i > 6 Or i >= 14 Then
           Writeline("My Name:")
        End If
    Next

This code works:

If i > 6 AndAlso i <= 14 Then Writeline "My Name:"

Above code wont work

3
  • 1
    Flip your sign. i <=14 Commented Sep 29, 2014 at 17:27
  • Can you show us the code for the loop too? There is more than one way to create a loop. Commented Sep 29, 2014 at 17:28
  • 1
    If you are not doing anything else within the loop, you could use For i As Integer = 6 To 14. It doesn't have to start at zero. Commented Sep 29, 2014 at 17:33

1 Answer 1

3
If i > 6 Or i >= 14 Then Writeline "My Name:"

this is the same thing as

If i > 6 Then Writeline "My Name:"

maybe you should use

If i > 6 AndAlso i <= 14 Then Writeline "My Name:"

(The issues is with your > and your or)

Sign up to request clarification or add additional context in comments.

6 Comments

Or, or And? Or even AndAlso.
yup, my bad, or would be all numbers! Edited
changed it just for you @Bjørn-RogerKringsjå ;)
Hmmm... did the OP mean to include the 6 when they said "from 6 to 14"?
@AndrewMorton i based the answer on the code provided, but yes, the answer might very well be i>=6
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.