Nesting IF-ELSE Statements in a Do Loop
Nesting IF-ELSE Statements in a Do Loop
I can't get the following to work.
* Start of the main loop
do i=1,10
* Now I want to do something conditional on iteration i.
if i>1
{
do j=1,n
set residSeries(j) gEnd+i-1 gEnd+i-1 = rv(gEnd+i-1)(j)
end do
}
else
{
do k=gStart,gEnd
do j=1,n
set residSeries(j) k k = rv(k)(j)
end do
end do
}
end if
end do
* Start of the main loop
do i=1,10
* Now I want to do something conditional on iteration i.
if i>1
{
do j=1,n
set residSeries(j) gEnd+i-1 gEnd+i-1 = rv(gEnd+i-1)(j)
end do
}
else
{
do k=gStart,gEnd
do j=1,n
set residSeries(j) k k = rv(k)(j)
end do
end do
}
end if
end do
You don't need the "end if" when the if-else is inside a loop (or any other compiled structure).
Also, you can simplify this to
(You can use "T" as a subscript for anything on the right side of the SET instruction.
Code: Select all
do k=gStart,gEnd
do j=1,n
set residSeries(j) k k = rv(k)(j)
end do
end do Code: Select all
do j=1,n
set residSeries(j) start end = rv(t)(j)
end do jIs that the case even if I have other instructions that must be executed after the "end if"? That would mean that RATS uses the curly brackets to determine the contents of the IF block. If so, in the code below, would RATS recognize that "Other stuff here" is to be done on each iteration but is not part of the IF block?You don't need the "end if" when the if-else is inside a loop (or any other compiled structure).
do i=1,10
Some stuff here
if i>1
{IF True stuff}
Else
{IF False stuff}
Other stuff here
end do i
That's correct. The {...} enclose the instructions covered by the IF and ELSE. The loop includes everything down to the END that matches the DO.
It's actually quite rare for an IF...ELSE block to be the only statements in a compiled section, so an END IF (which is more correctly END compiled stuff) is almost never needed.
It's actually quite rare for an IF...ELSE block to be the only statements in a compiled section, so an END IF (which is more correctly END compiled stuff) is almost never needed.