Showing posts with label and operator. Show all posts
Showing posts with label and operator. Show all posts

Wednesday, 14 March 2012

ASP: the AND operator

   


I've recently had an interesting mail exchange with one of the web thought reader about the ASP AND operator. I have used the AND operator in a previous post about alternating colours rows in a table and now I realise I haven't really explained how the AND operator works, and why it is useful in that situation and others.

If you try to output results, like our friend did, using a snippet like:
<%
   Dim i
   i=1
   while i<=15
      Response.Write("("& i &"," &(i and 2) &"),")
      i=i+1
   wend
%>
You get strange results. The series is:
(1,0),(2,2),(3,2),(4,0),(5,0),(6,2),(7,2),(8,0),(9,0),(10,2),(11,2),(12,0),(13,0),(14,2),(15,2),
That obviously raise a question: why we get that result?
And further more: how, in the end, is the AND operator working?