EasyManuals Logo

Mitsubishi MELFA CR1D User Manual

Mitsubishi MELFA CR1D
458 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
Page #213 background imageLoading...
Page #213 background image
4MELFA-BASIC IV
Detailed explanation of command words 4-200
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Ã…~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.
[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.
(3) A run-time error occurs under the following conditions.
*The counter's <Default Value> is greater than <End Value> and <Increment> is a positive number.
*The counter's <Default Value> is smaller than <End Value>, and <Increment> is a negative number.
(4) A run-time error occurs if a For statement and a Next statement are not paired.
(5) When the Next statement corresponds to the closest For statement, the variable name in the Next state-
ment can be omitted. In the example, "M2" in step 5 and "M1" in step 6 can be omitted. The processing
speed will be slightly faster to omit the counter variable.
For[]<Counter> = <Default value> To <End Value> [Step <Increment>]
:
Next[] [<Counter 1>]

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Mitsubishi MELFA CR1D and is the answer not in the manual?

Mitsubishi MELFA CR1D Specifications

General IconGeneral
BrandMitsubishi
ModelMELFA CR1D
CategoryController
LanguageEnglish

Related product manuals