Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi
How do I select which particular loops to skip. Depending on a condition I may want to skip loop "k" or "j" or "k" AND "j" and just get the next "i"
How do I go about doing that in similar scenario to below:
Solved! Go to Solution.
Can you explain what the reasoning behind your mod condition is?
If the only goal is to eliminate the rows which contain at least one character of "Reject", this function might do the job:
The function is not ORIGIN-aware, so ORIGIN=0 is assumed.
The "break" isn't mandatory. If you delete it, the function is just working a little bit more inefficient because every time ALL characters in "Reject" are tested even after a character was already found in the string.
Yo can use not the for but the while loop.
How about putting a "break" command in the else branch and also an "if Flag=1 break" after the k-loop to also skip the j-loop ?
I think the break function will work for me but I will need to do the following in the programming
Run a for loop
Read a file (Has rows of data)
Carry out Operations (This results in some rows of data removed)
I want to use the “new” data file to be read read again ( I dont know how to create the file and then get it to read it as a new file for the next iteration)
Keep doing till loop finished and data weeded out.
I think it may be an append or just a new writetext function function ?
Thanks for your help.
From your description I see no need to write the intermediate data to a new file in each iteration step just to read in this file in the next iteration.
Wouldn't it suffice to read in the file just at the beginning and only write the final data to a new file at the end ?
Which command you use to read and write the files depends on the data format of the file you have - csv, excel, text in columns, ....
This is where I need to set "Ans" to be reallocated the new file/data (ie this will now be the new file to be read
So how do I make the Ans become the new "String"?
So how do I make the Ans become the new "String"?
After the complete vector "Ans" has been calculated you would simply write "String <- Ans", overwriting "String" and so should have the same effect as writing "Ans" to a file and immediately reading it in to variable "String".
The only problem may be the index "reject" which determines the element in vector "String" used to compare with all the other elements of "String". Your code snippet dos not show how this index would be derived and if it changes with every iteration step or if its always the same constant string (in which case you would assign it a normal variable at the top of the program and use this for all subsequent comparisons).
One additional minor points I noticed: Should "Temp" really be an indexed variable? Do you really need to keep all different values? Wouldn't a normal variable (which then is overwritten in every step) suffice?
The index i is is from 0 to how many rows are in the file. So it will change as data is removed. Temp does not need index
@ppal wrote:
The index i is is from 0 to how many rows are in the file. So it will change as data is removed.
Yes, the loop starts from a new after the assignment "String <- Ans" was done
Temp does not need index
OK, I thought so.
Hi
The index "reject" is fixed as works ok. The isssue is with "i" The string index as this value changes as the file becomes smaller.
You may consider posting your worksheet along with a sample data. Its cumbersome to debug a picture.
It also would help if you describe in detail you would like to achieve with your program.
Nonetheless some remarks:
You should not use string[reject but rather a separate variable because String changes in the program loop.
In the last if you redefine String in a way so that String probably gets less elements so the outer loop eventually must fail. It may help to change the outer loop to a while loop using an appropriate condition.
Both of your breaks only exit the "k" loop. After, for example, your program finds the first "reject" character, it goes and looks for the second "reject" character. If that character isn't in the string and your modulus condition is met, then the program will add the string to Ans. You need to arrange your code so that a rejection of a character exits both the "j" and "k" loops.
Stuart
Can you explain what the reasoning behind your mod condition is?
If the only goal is to eliminate the rows which contain at least one character of "Reject", this function might do the job:
The function is not ORIGIN-aware, so ORIGIN=0 is assumed.
The "break" isn't mandatory. If you delete it, the function is just working a little bit more inefficient because every time ALL characters in "Reject" are tested even after a character was already found in the string.
And here's a variation on the theme, for purely pedagogical purposes (and to squeeze in an alliteration).
The example shows both the use of a local function to do the checking and of the for loop to iterate over a vector without the need for a loop iteration variable. It also demonstrates the use of boolean operations to update the keep/reject variable.
The (slightly) modified version of the function below shows how a local function can effectively use a main function argument as a "global" variable, thereby removing the need to pass the rejection string as an argument to the local function.
Mathcad Prime 7 worksheet attached.
Stuart