Mitsubishi Electric CR750-Q Instruction Manual page 255

Cr750/cr751/cr760 series
Hide thumbs Also See for CR750-Q:
Table of Contents

Advertisement

For - Next (For-next)
[Function]
Repeatedly executes the program between the For statement and Next statement until the end conditions
are satisfied.
[Format]
For[]<Counter> = <Default value> To <End Value> [Step <Increment>]
:
Next[] [<Counter 1>]
[Terminology]
<Counter>
<Default Value>
<End Value>
<Increment>
[Reference Program]
(1) A program that adds the numbers 1 to 10
1 MSUM=0
2 For M1=1 To 10
3 MSUM=MSUM+M1
4 Next M1
(2) A program that puts the result of a product of two numbers into a 2-dimensional array variable
1 Dim MBOX(10,10)
2 For M1=1 To 10 Steo 1
3 For M2=1 To 10 Step 1
4 MBOX(M1,M2)=M1*M2
5 Next M2
6 Next M1
(3) Process of the For-Next can be skipped by Break
1 MSUM=0
2 For M1=1 To 10
3 MSUM=MSUM+M1
4 If M_In(8)=1 Then Break
5 Next
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.
Describe the numerical variable that represents the counter for the number of repetitions.
Same for <Counter 1> and <Counter 2>.
Set default value of the counter for the number of repetitions as a numeric operation
expression.
Set the end value of the counter for the number of repeats as a numeric operation
expression.
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.
' Initialize the total MSUM.
' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
' Add M1 value to numeric variable MSUM.
' Return to step 2.
' Reserve space for a 10 x 10 array.
' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
' Increase the counter by 1 from 1 to 10 for the numeric variable M2.
' Substitute the value of M1*M2 for the array variable MBOX (M1, M2).
' Return to step 3.
' Return to step 2.
' Initialize the total MSUM.
' Increase the counter by 1 from 1 to 10 for the numeric variable M1.
' Add M1 value to numeric variable MSUM.
' If the input signal 8 is turned on, jump to Step 6.
' Return to step 2.
Detailed explanation of command words 4-235
4MELFA-BASIC V

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cr750Cr751-qCr751-dCr760-dCr760-qCr750-d

Table of Contents