Your program should match with with your requirement. Here all the solutions speak of different requirement.
Hi,
Option 1.
For()
command 1
if (twice) command 2
End loop
As I understood it,
>Loop starts
>Execute command 1
>Certain changes happen which is validated in next step
>if condition satisfies
>execute command 2
//Now, my question is, if output of command 1 is required for command 2? If yes, then this is perfect.
Option 2.
for()
command 1
end loop
if (twice)
for()
command 2
end loop
Here,
>Loop starts
>Command 1 executes n no of times and produces a certain scenario which is the end product of for loop execution.
>if condition satisfies
>loop starts
>executes command 2 for n no of times.
Diff. b/w opt 1 and 2:-
In opt 1 o/p of
each iteration of for loop is validated in next if condition and depending on that command 2 is executed or not.
Whereas, in opt 2, for loop execution ends and generates result, depending on that an if condition is validated and depending on that command 2 is executed.
In opt 1, command 2 may or may not execute all the iterations (as o/p of each steps are validated in next step. If the condition is static i.e. if o/p=7 (or true) then depending on the o/p of command 1 the command 2 would execute. e.g
Code:
sum=0
for i=1 to 10
sum=i+sum
if sum=9
print sum
end if
end loop
In opt 2, command 1 executes n no of times generates result, result is validated and depending on that command 2 gets executed n no of times,
above program as in opt2,
Code:
sum=0
for i=1 to 10
sum=i+sum
end loop
if sum=9
for j=1 to 10
print sum
end loop
end if
Option 3.
if (twice) then
for ()
command 1
command 2
end loop
else
for()
command 1
end loop
end if
here the scenario is totally diff.
>if condition is checked first
>if matched, enter loop
>execute command 1
>execute command 2
>end loop
>if condition not matched
>for loop starts
>command 1 executes
>loop ends
if I write it using the above example,
Code:
if condition=true
for i=1 to 10
sum=i+sum
print sum
end loop
else
for i=1 to 10
sum=i+sum
end loop
end if
Now, your task is to imagine the out put of all the examples I've used, u'd get your answer.