Not to make this a contest of "How many ways can you...", but I thought another example, using different logic, would also be instructive.
Code:
X VAR BYTE
LED1 VAR PORTB.1
LED2 VAR PORTB.2
X = 0 ' Reset Iteration Count
Loop:
IF X < 3 THEN ' Iterations 0,1,2
HIGH LED1
PAUSE 500
LOW LED1
PAUSE 500
ELSE ' Iterations 3,4,5
HIGH LED2
PAUSE 500
LOW LED2
PAUSE 500
ENDIF
X = X + 1 ' Increment Iteration Count
IF X < 6 THEN Loop ' Loop back if less than 6 iterations
END
So, now you have examples using all of the following:
FOR...NEXT
WHILE...WEND
REPEAT...UNTIL
IF...THEN
All of these will produce the same results, just with subtle differences in the logic used to accomplish the task, making this tread a nice little study.
HTH,
SteveB
Bookmarks