EasyManua.ls Logo

Mitsubishi Electric CR760-D - Page 255

Mitsubishi Electric CR760-D
730 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
4MELFA-BASIC V
Detailed explanation of command words 4-235
For - Next (For-next)
[Function]
Repeatedly executes the program between the For statement and Next statement until the end conditions
are satisfied.
[Format]
[Terminology]
<Counter> Describe the numerical variable that represents the counter for the number of repetitions.
Same for <Counter 1> and <Counter 2>.
<Default Value> Set default value of the counter for the number of repetitions as a numeric operation
expression.
<End Value> Set the end value of the counter for the number of repeats as a numeric operation
expression.
<Increment> Set the value of the increments for the counter for the number of repetitions as a numeric
operation expression. It is allowed to omit this argument, including Step.
[Reference Program]
(1) A program that adds the numbers 1 to 10
1 MSUM=0 ' Initialize the total MSUM.
2 For M1=1 To 10 ' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
3 MSUM=MSUM+M1 ' Add M1 value to numeric variable MSUM.
4 Next M1 ' Return to step 2.
(2) A program that puts the result of a product of two numbers into a 2-dimensional array variable
1 Dim MBOX(10,10) ' Reserve space for a 10 x 10 array.
2 For M1=1 To 10 Steo 1 ' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
3 For M2=1 To 10 Step 1 ' Increase the counter by 1 from 1 to 10 for the numeric variable M2.
4 MBOX(M1,M2)=M1*M2 ' Substitute the value of M1*M2 for the array variable MBOX (M1, M2).
5 Next M2 ' Return to step 3.
6 Next M1 ' Return to step 2.
(3) Process of the For-Next can be skipped by Break
1 MSUM=0 ' Initialize the total MSUM.
2 For M1=1 To 10 ' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
3 MSUM=MSUM+M1 ' Add M1 value to numeric variable MSUM.
4 If M_In(8)=1 Then Break ' If the input signal 8 is turned on, jump to Step 6.
5 Next ' Return to step 2.
6 If M_BrkCq=1 Then Hlt
[Explanation]
(1) It is possible to describe For-Next statements between other For-Next statements.Jumps in the program
caused by the For-Next instruction will add one more level to the control structure in a program. It is
possible to make the control structure of a program up to 16 levels deep. An error occurs at execution if
16 levels are exceeded.
(2) If a GoTo instruction forces the program to jump out from between a For statement and a Next state-
ment, the free memory available for control structure (stack memory) decreases. Thus, if a program is
executed continuously, an error will eventually occur. Write a program in such a way that the loop exits
when the condition of the For statement is met.
For[]<Counter> = <Default value> To <End Value> [Step <Increment>]
:
Next[] [<Counter 1>]

Table of Contents

Related product manuals