11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.26. FOR … NEXT … [STEP]<strong>PICBASIC</strong> <strong>PLUS</strong> CompilerSyntax : FOR Variable = Startcount TO Endcount [ STEP { Stepval } ]{code body}NEXTOverview :Operators :Example 1 :The FOR…NEXT loop is used to execute a statement, or series ofstatements a predetermined amount of times.Variable refers to an index variable used for the sake of the loop. Thisindex variable can itself be used in the code body but beware of alteringits value within the loop as this can cause many problems.Startcount is the start number of the loop, which will initially be assignedto the variable. This does not have to be an actual number - itcould be the contents of another variable.Endcount is the number on which the loop will finish. This does nothave to be an actual number - it could be the contents of anothervariable.Stepval is an optional constant or variable by which the variable increasesor decreases with each trip through the FOR-NEXT loop. Ifstartcount is larger than endcount, then a minus sign must precedestepval.‘ Display in decimal, all the values of WRD within an upward loopDIM Wrd as WORDFOR Wrd = 0 TO 2000 STEP 2PRINT @Wrd,” “NEXT‘ Perform an upward loop‘ Display the value of WRD‘ Close the loopExample 2 :‘ Display in decimal, all the values of WRD within a downward loopDIM Wrd as WORDFOR Wrd = 2000 TO 0 STEP -2PRINT @Wrd,” “NEXT‘ Perform a downward loop‘ Display the value of WRD‘ Close the loopNotes :You may have noticed from the above examples, that no variable ispresent after the NEXT command. A variable after NEXT is purely optional.FOR-NEXT loops may be nested as deeply as the memory on thePIC will allow. To break out of a loop you may use the GOTO commandwithout any ill effects.See also :REPEAT-UNTIL , WHILE-WEND61Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!