While loop workaround

Hi

I’m trying to do a while loop workaround. My idea is that I have a loop running to size #j which then expands every time a criteria is not met.

However, it would seem that the number of times a loop runs is fixed and unchangeable when it enters the loop the first time, is that really true?
Please see my code example below:

let#j 1
loop#i #j
    if #i < 5
        let#j #j+1
    endif
endloop

Is there another workaround?

You can also control the loop with an exit condition:
Let#j 1
Loop#i
Let#j #j+1
EndLoop #i<5

See basics manual page 9-12

1 Like

Thanks for the reply, that may actually work, but I’ve encountered another problem.

The whole purpose of this exercise is to create a way to see what my lists contains. For that I’ve made a definition which prints the values of the list to a “print.txt” file.

I have my code here:

#DEFINE PRINT
    <TEXT,FILE=Print.txt>
    List of the Variables:
    Name:           Value:
    </TEXT>
    
    loop#j var
        let#Current_Variable #Var(#j)
        <TEXT,FILE=+Print.txt>
        # Variable(#j) #(#Current_Variable,8.3)
        </TEXT>
    endloop
#ENDDEF

+prog template urs:18.1
    let#A 63816,681,31,323,51.3,121,3851.34,1381
    let#Var #A
    #INCLUDE Print
end

The problem with the definition is that it only runs once and not through the entire length of the list.
I suspect it’s due to the “loop#j var” part.
And I therefore tried to make a loop which would count the length of the list #Var inside the definition, but I can’t seem to get that to work either.

Any ideas?

Unfortunately cadinp does not work that way.
When you write:
Let#Var #A
You are (implicitly) writing:
Let#Var(0) #A(0)

If you insist on using a predefined block you should write:

Del#Var $ Delete it just in case
Loop#1 A
Let#Var(#1) A(#1)
EndLoop

Hello,

please check out the following code:

#DEFINE PRINT
    <TEXT,FILE=Print.txt>
    List of the Variables:
    Name:           Value:
    </TEXT>
    
    loop#j Var
        let#Current_Variable #Var(#j)
        <TEXT,FILE=+Print.txt>
        # Variable(#j) #(#Current_Variable,8.3)
        </TEXT>
    endloop
#ENDDEF

+prog template urs:18.1
    let#A 63816,681,31,323,51.3,121,3851.34,1381
    let#Var #A(:)     $ Read the Manual, Chapter 8.2.14       <-------------- Phil
    #INCLUDE Print
end

Greetings from NRW
Phil

1 Like

Wonderful, works like a charm! Thank you :slight_smile: