Graph from For Loop

hello,
I have a problem with one of my applications I am developing.
I calculate a timeSeries and I need to graph it on linechart. The timeSeries is calculated through an iteration of For Loop
I have tried to write in an array, but it didn't work since I can only take one value.
I tried to write the value in a datagrid but that didn't work either!
not because it is impossible, but because I am an idiot
http://alimsyed.com

Hi Dimitris,
Thanks for the post and I hope your well today.
You can achieve this by using a reference of the graph from the main VI, pass it to the subVI vi and use a property node to update the graphs value. 
I have attached an edit of your code to show this, labVIEW 8.6. 
Kind Regards
James Hillman
Applications Engineer 2008 to 2009 National Instruments UK & Ireland
Loughborough University UK - 2006 to 2011
Remember Kudos those who help!
Attachments:
mainVI.vi ‏9 KB
subVI.vi ‏13 KB

Similar Messages

  • Plot XY graph from while loop

    I am trying to make a curve tracer with a DC power supply, DAQ, and Labview 7.1. Everything is ok, until I want to plot an x-y plot from a while loop. I can do this function fine using a for loop and cluster cells, but I need the while loop for the interruption function. When I change to the while loop, it had data formating issues, but I believe I have it to something that should work. It seems like my xy plots want to graph (the auto scale moves the axis respectively) but I do not get a line. I'm not sure if Labview is seing this as just one point and not an array, or if there is a labview bug. Attached is my code with a few different trials to make an xy plot. If anyone can be of help I would be very thankful.
    -Jon
    Attachments:
    Curve_trace_w_relays_while.vi ‏122 KB

    If it works in a FOR loop, but nor in a while loop, most likely your output tunnels are not autoindexing (FOR: on by default, WHILE: off by default). Right-click on the output tunnels and select "enable indexing".
    If you want to watch your graph update during the while loop, you could accumulate your x and y data in a shift register and graph it. (See attached modification).
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Curve_trace_w_relays_whileMOD.vi ‏74 KB

  • Display text in label from 'for loop'

    Hi
    I'm new to Java, in fact so new just started yesterday.
    I'm trying to display all the values from a for loop into a label control in my application.
    Problem is, its only displaying the last number. Can anyone please help.
    Thanks
    George
    --------------------------------------------Code----------------------------------------------
    int lottoNumbers1 = Integer.parseInt(txtLotteryNumbers1.getText());
            int lottoNumbers2 = Integer.parseInt(txtLotteryNumbers2.getText());
            int lottoNumbers3 = Integer.parseInt(txtLotteryNumbers3.getText());
            int lottoNumbers4 = Integer.parseInt(txtLotteryNumbers4.getText());
            int lottoNumbers5 = Integer.parseInt(txtLotteryNumbers5.getText());
            //int lottoNumbers6 = Integer.parseInt(txtLotteryNumbers6.getText());
            int arrUserInput[] = {lottoNumbers1, lottoNumbers2, lottoNumbers3, lottoNumbers4, lottoNumbers5};
            int arrRnd[] = new int[5];
            Random rnd = new Random();
            for (int i = 0; i < arrRnd.length; i++) {
                arrRnd[i] = rnd.nextInt(49);
            boolean isfound = false;
            for (int i = 0; i < arrUserInput.length; i++) {
                isfound = false;
                for (int j = 0; j < arrRnd.length; j++) {
                    if (arrUserInput[i] == arrRnd[j]) {
                        isfound = true;
                if (isfound) {
                    //System.out.println("Same Numbers again : " +arrUserInput[i]);
                    String numbers = Integer.toString(arrUserInput[i]);
                    int res = NumberCount.wordcount(numbers);
                    //System.out.println("Number of matches : " +res);
                    switch (res) {
                        case 1:
                            lblNumbersEntered.setText("You matched 1 number " + arrUserInput[i] + " and win nothing");
                            System.out.println("Number of matches : " +res);
                            break;
                        case 2:
                            lblNumbersEntered.setText("You matched 2 number " + arrUserInput[i] + " and win £2");
                            System.out.println("Number of matches : " +res);
                            break;
                        case 3:
                            lblNumbersEntered.setText("You matched 3 number " + arrUserInput[i] + " and win £10");
                            System.out.println("Number of matches : " +res);
                            break;
                        case 4:
                            lblNumbersEntered.setText("You matched 4 number " + arrUserInput[i] + " and win £50");
                            System.out.println("Number of matches : " +res);
                            break;
                        case 5:
                            lblNumbersEntered.setText("You matched 5 number " + arrUserInput[i] + " and £1000");
                            System.out.println("Number of matches : " +res);
                            break;
                        default:
                            lblNumbersEntered.setText("You have matched no numbers");
                            System.out.println("Number of matches : " +res);
                            break;

    If you want a complete history of each time you go through the loop, you have to construct the history:
    [code]
    myLabel.setText("This");
    MyLabel.setText(" is");
    myLabel.setText(" good");
    [/code]
    myLabel will contain only " good", since that is what myLabel was set to last, but if you want the history:
    [code]
    myLabel.setText("This");
    MyLabel.setText(myLabel.getText() + " is");
    myLabel.setText(myLabel.getText() + " good");
    [code]
    Should give you "This is good", as each time the contents of myLabel are retrieved and appended before myLabel is given the new set value.

  • Is it possible possible to exist from FOR loop while executing

    Hi
    Like break in C, is it any method available in LabVIEW to exist from a FOR LOOP while executing.
    thanks in advance

    No. You have to use a while loop.

  • Pick up specific indices from for loop

    hi guys , 
    i have a for loop with N = 60 , i'm trying to make something when the index (i) reachs specific number , the indecies i'm interested in are
    1 ,5 , 9,13, 17, 22, 26, ,30,34,38,43,47,51,55,59
    the difference is 4 in some of them but it changes to 5 @ 22 and 43 and come back to 4 in between .
    can anybody help me pick up these indecies ?
    Solved!
    Go to Solution.

    Why would you need a mathematical formula?
    What is a "boolean variable"? In the context of LabVIEW, you need to explain in more detains what you mean )
    I would just do something similar to the following (The second loop will iterate 60 times):
    Note that the parts on the left will be folded into a single boolean array constant at compile time, so there is no overhead during execution.
    (You can also do it all in a single loop. try it. )
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    IrregularSelection.png ‏16 KB

  • Problem  in out from for loop

    Here i drew connect four board game which has 6 row and 7 columns . There is an additional row appear . How can i out from loop to not draw seven rows. ??
    import java.awt.Dimension;
    import javax.swing.JFrame;
    public class TestNet extends JFrame {
        private DrawingNet drawingNet;
        public TestNet() {
            drawingNet = new DrawingNet();
            getContentPane().add(drawingNet);
        public static void main(String[] args) {
            TestNet testNet = new TestNet();
            testNet.setDefaultCloseOperation(TestNet.EXIT_ON_CLOSE);
            testNet.setSize(new Dimension(600, 300));
            testNet.setLocationRelativeTo(null);
            testNet.setVisible(true);
            testNet.setExtendedState(MAXIMIZED_BOTH);
    import java.awt.Color;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    class DrawingNet extends JPanel {
        private int X_START = 100, Y_START = 100, DISTANCE = 0;
        private static final int ROW = 6, COL = 7;
      //  private final int[][] arrayNet;
        public DrawingNet() {
        //    arrayNet = new int[ROW][COL];
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            for (int c = 0; c < COL; c++) {
    //            if (c ==7 ) {
    //                break;
                for (int r = 0; r < ROW; r++) {
    //                if (r == 5) {
    //                    break;
                    g.drawLine(X_START, Y_START + DISTANCE, X_START * COL, Y_START + DISTANCE);
                    g.drawLine(X_START + DISTANCE, Y_START, X_START + DISTANCE, Y_START * ROW);
                DISTANCE += 100;
    }Thanks

    if you compile my code you will see board consist of 6 row and seven column but there is seven row under the board i want not draw this
    how can i stop loop from drawing this row ??
    i do like this but also it is appear:
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(Color.BLACK);
            for (int c = 0; c < COL; c++) {  // col from 0 to 6  (7 columns)
                for (int r = 0; r < ROW; r++) {  // row from 0 to 5  (6 rows)
                    g.drawLine(X_START, Y_START + DISTANCE, X_START * COL, Y_START + DISTANCE);
                    g.drawLine(X_START + DISTANCE, Y_START, X_START + DISTANCE, Y_START * ROW);
                    if (r == 6) {  // the  goal from this to not draw  the seven row
                        continue;
                DISTANCE += 100;
        }Many thanks .
    Edited by: beshoyatefw on Mar 21, 2010 6:18 AM

  • Exclude from for loop

    Hi,
    I have this script and error :
    Declare
    Cursor C1 is
    select d.product_code,b.responsibility_key from FND_USER_RESP_GROUPS_ALL a,fnd_responsibility b,fnd_user c,fnd_application d
    where a.user_id = c.user_id
    and a.responsibility_id = b.responsibility_id
    and b.application_id = d.application_id
    and c.user_name ='SYSADMIN'; -- user you want to copy
    v c1%rowtype;
    BEGIN
    for v in c1 loop
    FND_USER_PKG.AddResp('MYUSER',v.product_code, v.responsibility_key,
    'Standard', 'DESCRIPTION', sysdate, null);
    end loop;
    END;
    ERROR at line 1:
    ORA-20001: APP-FND-02604: Invalide data
    APPLICATION_SHORT_NAME=OE, RESPONSIBILITY_KEY=ORDER_ENTRY_SUPER_USER,
    SECURITY_GROUP=Standard.
    ORA-06512: Ó "APPS.APP_EXCEPTION", ligne 70
    ORA-06512: Ó "APPS.FND_USER_PKG", ligne 2140
    ORA-06512: Ó ligne 11
    How can I exclude the case RESPONSIBILITY_KEY=ORDER_ENTRY_SUPER_USER,in my for v in c1 loop ? For example :
    if v.responsibility_key=ORDER_ENTRY_SUPER_USER then go to next.
    Many thanks.

    If I have understood it correctly...
    If you dont want to see this value at all, then probably by adding this condition to where clause of the select query (of the cursor). Or trying out something with parameterised cursors.
    Sidhu
    Message was edited by:
    Sidhu

  • Read data from text file one by one using for loop

    Dear Forum
    I want to read data of single colum of text file inside the for loop one by one(for each iteration value must be replaced by another value of text file).This value is used by a formula inside for loop. also after completion of iterations the values must be plotted on xy graph. How to do it.? please help me.
    profravi

    It's not very efficient to read a file line by line. Much simpler to read it all at once and then auto-index the results inside a for loop. The image below shows a generic solution to your problem. This assumes that the data in the file is in a single column.
    I would also recomend checking ou the learning LabVIEW resources here.
    I would aslos suggest that since this type of question is not specific to either NI-Elvis or the LabVIEW SE, you should post similar questions to the LabVIEW board. If you have problems, attaching a sample of the text file would help.
    Message Edited by Dennis Knutson on 10-18-2007 09:11 AM
    Attachments:
    XY Graph From File.PNG ‏4 KB

  • Real-time updates of an XY graph with a 2D array (x,y) inside a for-loop

    Hi all,
       I am new to this forum, and relatively new to LabView (I've used TestPoint in the past), and I have a question. I have implemented a for-loop to grab data from an LCR meter (via GPIB) which becomes the Y data. The X data is calculated and tunneled into the for loop (although varies with incrementing 'i'). Anyhow, I am trying to store all of the data and keep the user updated throughout the test by plotting the XY Graph each iteration. Right now, the XY Graph plots one point at a time, so somehow the data I am appending to the 2D array (x,y data) is getting overwritten each itteration. How can I make it so that each new point is added to the array, making it bigger so that the data will be saved and so that the user will be able to see all the data in real-time on the graph as the test in running?
    Thanks
    P.S. I would post a screenshot, but I'm not sure how to upload here.

    Hey Mendeleev3104,
    There is an attachment section at the bottom of the post when creating or editing a post. You might want to use that to attach a picture of your code.
    None the less I will give a shot with some suggestions without viewing your code.
    You should look into using shift registers along with the Insert Into Array.vi to build an array of numbers. A good source of information for shift registers can be found in the For Loop and While Loop Structures help.
    Hopefully this helps!!
    Aashish M
    Applications Engineer
    National Instruments
    http://www.ni.com/support/

  • For loop stop in sub vi from main vi?

    Hi! I want to control from my main vi a sub vi consisting of a stepped sine function generator. This sub vi has a for loop. The problem is that I want to have the option of terminating the loop in the sub vi from the main vi. I tryed using global variables or an event stucture. The problem is that, in both cases, the "stop" variable in my main vi is only updated after the loop terminates in the sub vi. Can anyone please help me? Thank you very much.
    Best regards,
    Diogo Montalvão (Lisbon, Portugal)

    hong2011 wrote:
    I found this thread very helpful. May I ask one thing - what is the purpose of the Occurrence?? If I try it without implementing the Occurrence (neither in main VI or subVI), labview crashes when the subVI completes its task or is stopped from the mainVI.
    A lot of things changed in the last 6 years, so this thread is a bit stale and there are a few other ways to do it. (For example we can have a FOR loop with a conditional terminal).
    You don't provide enough information to answer your question why it crashes. It would be more interesting to know what you are "using" and not what you are "not using". This is not something we can guess by elimination.
    LabVIEW should never crash, so please show us the code that crashes so NI can fix it. What LabVIEW version are you using?
    LabVIEW Champion . Do more with less code and in less time .

  • A tunneled Excel refnum goes from a valid value to a NULL between iterations of a For Loop?

    How would a tunneled Excel refnum go from a valid value to a NULL between iterations of a For Loop?
    For
    some reason this works find in one VI and when executed and not in
    another.  Here's screen shots of the highlighted execution with probes
    appropriately. The "Open" refnum is passed into "Performance Test -
    Write Data To Files.vi".  That's where the trouble is.  You can see
    that it goes into the For Loop.  The first iteration is okay, but the
    second and subsequent iterations have the refnum NULL.  See images
    below.
    (I don't know how to delete an accidental double post, sorry)
    Message Edited by James DiLiberto on 01-22-2008 01:48 PM
    Attachments:
    Second Iteration1.jpg ‏158 KB
    First Iteration1.jpg ‏145 KB
    Second Iteration Error Dialog1.jpg ‏20 KB

    Is there any chance that the Insert Data Into Excel VI is closing the reference or that it is closed anywhere else (e.g. through a local or by having its owner destroyed)?
    I wouldn't expect the numeric value of the reference to change to 0, but since ActiveX is an external resource, I suppose that it's possible that the probe shows the number only if the resource is actually accessible.
    Try to take over the world!

  • Remove text field from Array via for loop

    Hi,
    i have a problem to remove text fields added via for loop.
    That im doing is, via for loop im dynamically creating menu with 10 buttons.
    Each button contain, dynamically created, background (shape) and text field.
    And everything is fine.
    But when im try to remove text fields then i got this error:
    - Im using button to remove text fields - lang_btn.addEventListener(MouseEvent.CLICK, clickHandler);
    ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
              at flash.display::DisplayObjectContainer/removeChild()
              at Loading_Img_fla::MainTimeline/xmlLoaded()
              at flash.events::EventDispatcher/dispatchEventFunction()
              at flash.events::EventDispatcher/dispatchEvent()
              at flash.net::URLLoader/onComplete()
    In the script bellow marked with red is what should remove text fields from an Array, instead giving me error.
    Here is my script
    // Create for loop
    for (var i:int = 0; i < 10; i++)
              for each (xml in listItems)
                        if (i == xml.attribute("Id"))
                                  // Add MovieClip to stage to hold the data
                                  addChild(lmHolder);
                                  lmHolder.x = 0;
                                  lmHolder.y = 0;
                                  // Create new MovieClip to hold buttons
                                  lmButtonsMCArray[i] = new MovieClip();
                                  lmButtonsMCArray[i].buttonMode = true;
                                  lmButtonsMCArray[i].mouseChildren = false;
                                  lmButtonsMCArray[i].x = 20;
                                  lmButtonsMCArray[i].y = 20 + btCount * buttonSpace;
                                  // Add each button MovieClip to lmHolder MovieClip
                                  lmHolder.addChild(lmButtonsMCArray[i]);
                                  // Create Background to buttons
                                  lmButtonsArray[i] = new Shape();
                                  lmButtonsArray[i].graphics.beginFill(lmBgColor0, 1);
                                  lmButtonsArray[i].graphics.drawRect(0, 0, 230, 85);
                                  lmButtonsArray[i].x = 0;
                                  lmButtonsArray[i].y = 0;
                                  // <<-- Add Background shape to the buttons MovieClips
                                  lmButtonsMCArray[i].addChild(lmButtonsArray[i]);
                                  // Create a new array to preserve data from XML List
                                  lmNameArrayEG = new Array();
                                  lmNameArrayUS = new Array();
                                  // Create local variable to hold
                                  var lmTxtFieldContentUS:String;
                                  var lmTxtFieldContentEG:String;
                                  var lmTxtContent:String;
                                  // If clicked button is EG then make array with Arabic text
                                  // If clicked button is US then make array with English text
                                  if (footer.lang_btn.langState == "EG")
                                            for each (var leftMenuName:XML in egLanguageList)
                                                      lmNameArrayEG.push(leftMenuName);
                                            lmTxtFieldContentEG = lmNameArrayEG[i];
                                            lmTxtContent = lmTxtFieldContentEG;
                                  else
                                            for each (var leftMenuNameUS:XML in usLanguageList)
                                                      lmNameArrayUS.push(leftMenuNameUS);
                                            lmTxtFieldContentUS = lmNameArrayUS[i];
                                            lmTxtContent = lmTxtFieldContentUS;
                                  // Setup new text field each time script is executed
                                  lmTxtFieldsArray[i] = new TextField();
                                  lmTxtFieldsArray[i].width = 110;
                                  lmTxtFieldsArray[i].border = false;
                                  lmTxtFieldsArray[i].wordWrap = true;
                                  lmTxtFieldsArray[i].multiline = true;
                                  lmTxtFieldsArray[i].selectable = false;
                                  lmTxtFieldsArray[i].embedFonts = true;
                                  lmTxtFieldsArray[i].antiAliasType = AntiAliasType.ADVANCED;
                                  lmTxtFieldsArray[i].autoSize = TextFieldAutoSize.CENTER;
                                  lmTxtFieldsArray[i].text = lmTxtContent.toUpperCase();
                                  lmTxtFieldsArray[i].x = 10;
                                  lmTxtFieldsArray[i].name = "lmTxtFieldName" + i;
                                  // <<-- Add Text fields to the Movie Clip
                                  lmButtonsMCArray[i].addChild(lmTxtFieldsArray[i]);
                                  // If clicked button is EG then set Arabic text format, and make array with Arabic text fields
                                  // If clicked button is US then set English text format, and make array with Egnlish text fields
                                  if (footer.lang_btn.langState == "EG")
                                            lmTxtFieldsArray[i].setTextFormat(txtFormat_lm_eg);
                                            // Make array from text fields;
                                            pushEgTFintoArray.push(lmTxtFieldsArray[i]);
                                  else
                                            lmTxtFieldsArray[i].setTextFormat(txtFormat_lm_us);
                                            // Make array from text fields;
                                            pushUsTFintoArray.push(lmTxtFieldsArray[i]);
                                  // If clicked button is EG then loop thrue the for loop and remove English text fields from array
                                  // If clicked button is EG then loop thrue the for loop and remove Arabic text fields from array
                                  if (footer.lang_btn.langState == "EG")
                                            for (var rNr_us:Number = 0; rNr_us < pushUsTFintoArray.length; rNr_us++)
                                                      //remove the text field array from the display
                                       removeChild(pushUsTFintoArray[rNr_us]);
                                            //clear the array
                                            pushUsTFintoArray = [];
                                  else
                                            for (var rNr_eg:Number = 0; rNr_eg < pushEgTFintoArray.length; rNr_eg++)
                                                      //remove the text field array from the display
                                       removeChild(pushEgTFintoArray[rNr_eg]);
                                            //clear the array
                                            pushEgTFintoArray = [];
              btCount++;

    it looks like those tf's are children of  lmButtonsMCArray[i], not the current scope.  use:
    if (footer.lang_btn.langState == "EG")
                                            for (var rNr_us:Number = 0; rNr_us < pushUsTFintoArray.length; rNr_us++)
                                                      //remove the text field array from the display
                                        lmButtonsMCArray[rNr_us].removeChild(pushUsTFintoArray[rNr_us]);
                                            //clear the array
                                            pushUsTFintoArray = [];
                                  else
                                            for (var rNr_eg:Number = 0; rNr_eg < pushEgTFintoArray.length; rNr_eg++)
                                                      //remove the text field array from the display
                                        lmButtonsMCArray[rNr_eg].removeChild(pushEgTFintoArray[rNr_eg]);
                                            //clear the array
                                            pushEgTFintoArray = [];

  • Issues with nested for loops - saving images from a camera

    Hi all,
    I've written a vi. to capture a specific number of images ('Image No') and save these images, outputted to a folder of my choice.  Each image is identified sequentially.  However, I wish to do a number of iterations ('Run') of this capture sequence, such that the filename of each image would be 'Filename (Run)_(Image No).png', e.g. run 5, image 10 would be 'Filename 5_10.png'.  I have tried a nested for loop for this but I receive an error 'Asynchronous I/O operation in progress' (I've attached a printscreen).
    Can anyone assist me in solving this problem? I preiously posted this in machine Vision but got no response (http://forums.ni.com/t5/Machine-Vision/Capturing-image-sequences-issues-with-nested-for-loops/m-p/19...).  Please find attached my vi.
    Kindest regards and thanks,
    Miika
    Solved!
    Go to Solution.
    Attachments:
    Labview problem.jpg ‏3841 KB
    Image sequence save to file.vi ‏48 KB

    Miika,
    the problem is not the filenam, but the name of the folder (AHHHHH!). You try to create the same folder in the outer for loop over and over again.... (it is the error message above the '======', not below )
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Question about using for-loop to generate array from DAQmx. Thanks!

    I have a laser system with a frequency of 1kHz, I am using this 1kHz signal to trigger the DAQmx and get the data from a photodetector, e.g. I will get 1000 data points during 1 second from DAQmx, but I need to separate this 1000 data points into the even and odd list, which is two list of 500 data points, e.g.. The 1st, 3rd, ... 99th data is one array, the 2nd, 4th,... 10th data is another array, then I will do further calculations based on these two arrays.
    To seperate the even and odd data, the only way I can find is put these 1000 points into an array and then seperate them afterwards.
    Can I do things like this pic?
    I don't know the speed of the for loop, because the 1kHz trigger is always there, once it is triggered, the DAQmx read will give a data point, if the speed of the for-loop( the time from the end of a loop to the beginning of the next loop) is slower than the 1kHz trigger, then the for-loop will miss data point, then the ordering of the 1000 points in 1 second will be changed.
    Or I need to put everything, e.g. AI Voltage, Trigger, sample clock, into the for-loop and then return a Y? Thanks! 

    Clarification:
    The VI you have posted will work as following:
    1) The task will read 2 analog inputs (ai0, ai3).
    2) The acquisition starts, oncece digital signal (trigger) is detected on PFI0
    3) The sampling rate will be as specified in "rate" control - it is continuous analog input acquisition, which means that after trigger is received (point 2), the board will start to generate hardware clock with frequency you specify as "rate"
    4) with each rising edge of that hardware clock, the measurement is taken, and stored into buffer of driver.
    5) DAQmx read will try to read "number of samples per channel" number of samples each time is called - and if there is not enough measurement stored in buffer (step 4), then DAQmx read will wait until DAQ card will measure reaquested number of samples (or timeout occurs before requested number of samples has been acquired)
    6) DAQmx read will be then called 1000 times - so totaly you will read 1000 * "number of samples per channel"  number of samples.
    You do not have to be worried about speed of the loop. In fact, if you need to read just 1000 samples, with 1kS/s, then you can remove for loop and you can change measurement mode from continuous to finite samples, and specify number of samples to read to be 1000. You will read them all properly. I recomend you to read User Manual for your DAQ device - lets say M Series User Manual.
    I hope it is clear now.
    regards,
    stefo

  • How to recover the for loop or seq() from a sequence result

    assume generate a sequence with code
    for i in 1..2 do
        append 1 to a list to represent outer loop
        for j in 1..3 do
               append 2 to list to represent inner loop
    result in [1,2,2,2,1,2,2,2]
    is it possible to recover for loop code and seq() function code from [1,2,2,2,1,2,2,2] ?
    with fold or unfold or other method?
    computing nightmare

    Yes; and in doing so, your program will converge towards being an exemplar of the generalization of
    Greenspun's tenth rule to any arbitrary language (rather than just 'C' or Fortran).

Maybe you are looking for