Loop At <itab> TO <wa> Where <cond> does not find lines - loops

I have a problem with Loop through a using the condition that an attribute from one table is the same with the other. For better explaining i'll past the code. Is not something difficult but i don't understand where i make the mistake.
LOOP AT gt_spfli INTO wa_spfli.
AT NEW carrid.
WRITE:/ wa_spfli-carrid.
ENDAT.
LOOP AT gt_sflight INTO wa_sflight WHERE carrid EQ wa_sflight-carrid.
WRITE:/ wa_sflight-carrid,
wa_sflight-connid,
wa_sflight-price.
ENDLOOP.
ULINE.
ENDLOOP.
For every carrid in spfli i want to show what sflight contains for that carrid. But it only writes the wa_spfli-carrid. It never gets to second write. When i do debugging i get that wa_sflight is always empty. ( or never gets to it ) gt_sflight and gt_spfli is populated so where does the problem comes from? If i remove the "where carrid EQ wa_sflight-carrid" works... but is not what i want to be shown on screen.
Additional info ( don't know if it's useful ): the gt_spfli and gt_sflight is populated through a function module i made myself.

On the inner loop, you want to compare carrid with wa_spfli-carrid (which comes from the outer loop) and not with wa_sflight-carrid.

Related

How to add a break in a trial loop in PsychoPy

I'm learning how to work with PsychoPy. My problem is that I cannot add a break in a trial loop within another loop.
Situation:
There are two stimuli lists: ListA.xlsx and ListB.xlsx. Both lists contain 20 sentences. A third list ('AB.xlsx') refers to block A ('ListA.xlsx') and block B ('ListB.xlsx').
When I start the experiment, PsychoPy runs through the twenty sentences of ListA.xlsx in a loop. After block A, the experiment stops for a break. The participant can continue the experiment by pressing the spacebar. When the experiment resumes, PsychoPy runs through the twenty sentences of ListB.xlsx in a loop.
For the block break, I'm using the following code:
if blocks.thisTrialN not in [1] :
continueRoutine=False
Problem:
What I want to add is a break within block A and within block B, i.e. I want to add a break after 10 sentences. I've already tried many different things, but I don't get it to work.
I'd appreciate any advice!
In your "break" routine, insert a code component and put something like this in its "begin routine" tab:
if currentLoop.thisN != 9: # NB counting is 0-based
continueRoutine = False
Builder maintains a variable named currentLoop to refer to whatever loop is currently running, so this code and routine can be re-used in any loop in your experiment, without needing to refer to the name of the specific loop that is enclosing it.

Breakable loop in Scratch?

How do you make a breakable loop in Scratch? I'm using Scratch 2.0 and can't find any good way to make a loop breakable, from inside of the loop itself.
Disclaimer:
There is no perfect way to do it. If you can possibly stand this true fact then feel free to continue.
There are a few different ways you could do it.
With repeat until
The first and most simple one follows this:
But this isn't technically part of the script - it's just repeating until some value returns true.
With a custom block (stop this script)
In order to do it inside of the script, you'll need to use a sneaky little trick with custom blocks.
Create a custom block called whatever you want - but probably along the lines of "breakable loop". Inside of it, create this script:
By using stop script we are breaking out of the script that is currently running - which, according to Scratch, is the custom block.
See the result! (as scratchblocks)
With broadcast and wait
You could also use a broadcast-and-wait method, very similar to above:
Though I highly suggest you don't use this method, as if any other sprites have breakable loops you'll need to rename each one, which can be tedious after using a lot of loops in a lot of sprites!
(Note this bug has been fixed in version 442 of the editor and such the following no longer applies.)
Help! My project is lagging a bunch now!
As #foi has noticed, if your code must be run inside of a frame you probably checked run without screen refresh. Unfortunately, due to a bug in the Scratch player, this causes the program to essentially break after the stop this script block has been activated. How can you handle this?
It follows the same principle you use when you use a run without screen refresh custom block inside of a forever loop - the loop doesn't use screen refresh while the inside does, allowing for instant animations whether or not one is using turbo mode.
Here's an example - the image is really too long to be embedded, so see it here instead.
You can make a variable inside or outside of the repeat and make your script like this:
repeat until [[my variable] = [e.g: 1]]
your code
your code
your code
your code
end of repeat until
For a "repeat until" block the simplest way would be to "or" your normal until condition with the break condition in the until.
By adding an incremeting loop counter variable in the loop you can use a "repeat until" to replicate the function of a "repeat n times" block
By using a "repeat until" block with only your break condition you get the equivalent of a "forever" block
If you need another script/ sprite to trigger the break then a public variable will let you break the loop from anywhere and let a single condition break loops for different sprites.
I'd post an image of the blocks but this is my first reply and the site won't let me!
good luck
You can use these few ways to do it...
conditional loop
stop this script
if then else, in the else section, put nothing
I would prefer to use the first method, as it requires less blocks and for the first method, you can still add in code that will be executed after the loop has stopped executing.
You can make it repeat x times or make it have a certain point where it stops, such as another variable changing.
Otherwise, I don't think there is a wat to do that.
Use the repeat until block. Then put in an equals block or whatever into the boolean part. Then inside that repeat until block, put a stop this script block.
Hope this helps :D

C - Is there a way to remove a mvwprintw from my window? (Ncurses)

I want my mvwprintw statement to disappear after a point in the code. I don't know how delete the print statement though. Is there a print function that can do it? I tried by creating another statement full of spaces thinking it would overlap the existing statement and it would look blank. I tried looking online but could not find anything. Please let me know if there is a way.
You can clear the whole line by moving to the beginning of a line
move(3,0);
and then clearing the line
clrtoeol();
I actually found a way, hopefully this helps someone with the same problem in the future. All you need to do is to add \rat the beginning of your statement and it will over wright anything previously in that spot.
mvwprintw(win2,3,16,"Hi.");
mvwprintw(win2,3,16,"\rPlease make your first move."); //overwrites the "Hi"
mvwprintw(win2,3,16,"\rPlease make your second move.");//overwrites the "Please make your first move"
Adding blank spaces into the print statement would erase your previous message.

Matlab: Problem with deleting rows from an array if a certain condition is true

After creating a dataset array (data), I want to delete all rows for which Var4 takes a certain value. Here is what I've done so far:
for i=1:length(data.perf)
if data.Var4(i)==2
data(i,:)=[]
end
end
The problem of course is that the array gets shorter in every run the condition holds true, so that it stops before all lines are checked. When i=length(data.perf) the array is some 50 lines shorter. I think you guys get the problem. Can somebody please suggest me an elegant solution? I will have to do things like this quite often in the future.
Are you sure you want to loop to length(data.perf) and not just length(data)? It's not clear from the context but would make more sense...
First suggestion: Reversing your loop could solve the problem of the array getting shorter (for i = length(data.perf):-1:1...)
The more elegant solution would be to do it without a for loop
data(data.Var4==2, :) = [];

Foreach Loop Microsoft SSIS - equivalent to break statement

Within a Foreach loop in SSIS is there a way that if a task fails you can break out of the loop to the next iteration?
I am looping over xml files and performing a lookup using values within this file, if the lookup doesn't return any values i'd like to report on this and then not perform any other tasks for this file. If there is no equivalent to a break statement how else can this be achieved?
You could also use a 'for' loop with a boolean condition such as looping while a variable is equal to true. Then when you want to break out of that loop, simply change the value of that variable to false and then you will break out of the loop.
Answering your question...a foreach loop, loops over a collection and other enumerable constructs so long as they exist to loop over. So you could either find a workaround, or just use a 'for' loop instead of a 'foreach' loop. That way you have more of a programming type control over the loop because you set the condition expression.
And yet another way would be to put a sequence container into your loop then put the conditional steps in the sequence container. Any decision that should 'continue' need only exit the sequence container.
Very simple to implement with all the control you could want including error trapping.
The lookup can redirect if there are no values returned, away from the successful flow.
You need the rest of your foreach loop to know there has been an error, so one way would be to set a package variable on error, just before you do the logging.
Then, in the 'success' arrow after your lookup you can change it to a conditional success, so that it only proceeds if the value of the variable is not the error value.
So I just had that problem and solved it by a) directing the failed task to a dummy task which did nothing and ended and b) setting the 'FORCEEXECUTIONRESULTS' to 'SUCCESS', which plowed through just the way I wanted it to.

Resources