Skip to main content
18-Opal
April 28, 2022
Solved

SKIPPING PARTICULAR LOOPS in Programming

  • April 28, 2022
  • 2 replies
  • 5203 views

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:

ppal_0-1651108917124.png

 

Best answer by Werner_E

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:

Werner_E_0-1651576913712.png

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.

2 replies

24-Ruby IV
April 28, 2022

Yo can use not the for but the while loop.

25-Diamond I
April 28, 2022

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 ?

18-Opal
April 28, 2022

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.

25-Diamond I
April 29, 2022

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?