Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
For loop 重新启动do循环_For Loop_Fortran_Fortran90_Restart - Fatal编程技术网

For loop 重新启动do循环

For loop 重新启动do循环,for-loop,fortran,fortran90,restart,For Loop,Fortran,Fortran90,Restart,我有一个从1到n的do循环,它包含一个if语句。 如果满足要求,某些参数,包括n已经改变。 因此,我想再次开始整个do循环,从i=1开始,直到i=n,直到不再满足要求,并且i达到n。 但我不知道如何用fortran编程。 因为在当前情况下,do循环在if语句之后继续,如果if语句满足另一个i,它将覆盖以前的数据。如果每次满足需求时do循环都会重新启动,那么情况就不再是这样了。 有人知道如何用fortran 90编程吗 所以有一个数组包含一列数字。如果满足if语句,我想在列中插入一个额外的数字。因

我有一个从1到n的do循环,它包含一个if语句。 如果满足要求,某些参数,包括n已经改变。 因此,我想再次开始整个do循环,从i=1开始,直到i=n,直到不再满足要求,并且i达到n。 但我不知道如何用fortran编程。 因为在当前情况下,do循环在if语句之后继续,如果if语句满足另一个i,它将覆盖以前的数据。如果每次满足需求时do循环都会重新启动,那么情况就不再是这样了。 有人知道如何用fortran 90编程吗

所以有一个数组包含一列数字。如果满足if语句,我想在列中插入一个额外的数字。因此,该点之前的所有数字都应保持不变,该额外点之后的所有点应向下移动一个,然后在创建的自由点中,额外点出现。这一切都很好。 但是,如果两次满足if语句,则必须添加两个点,但在必须添加第二个点时,它将覆盖添加第一个点后的数据。因此,如果可以从第一次的结果(包括额外的点)开始从头开始完全重新启动if循环,那么它将工作。 因此它应该从i=1开始,然后继续运行,直到满足if语句,执行if语句,再次从i=1开始,并重复此操作,直到i=n(每次添加一个点时,该值都会增加) 我看不出代码是如何相关的,但特别是对于您: prevnumbers是起始编号,它遵循一些步骤生成编号。如果then编号不符合If语句,则必须更改原始编号(PrevNumber),然后再次执行步骤

do i = 1,n
    if (numbers(i,1) >= x) then
    !this part will transfer the previous numbers to the new numbers until the new point
        do j=1,i
            numbers(j,1)=prevnumbers(j,1)
        end do
        !This part will move the numbers after the new number one ahead so a free spot is created
        do j=n,i,-1
            numbers(j+1,1)=prevnumbers(j,1)
        end do
        !this part adds the new number and increases n by 1.
        numbers(i+1,1)=(prevnumbers(i,1)+prevnumbers(i+1,1))/2
        n=n+1
    end if
end do

如果您事先不知道迭代的确切次数,那么首先可能不应该使用带有索引的do循环。没有测试

i = 0
do
   i = i + 1
   if (i>n) exit

    if (numbers(i,1) >= x) then
    !this part will transfer the previous numbers to the new numbers until the new point
        do j=1,i
            numbers(j,1)=prevnumbers(j,1)
        end do
        !This part will move the numbers after the new number one ahead so a free spot is created
        do j=n,i,-1
            numbers(j+1,1)=prevnumbers(j,1)
        end do
        !this part adds the new number and increases n by 1.
        numbers(i+1,1)=(prevnumbers(i,1)+prevnumbers(i+1,1))/2
        n=n+1
    end if
end do

for循环不适合您的问题,请使用do-while循环

i=1
do while(i<=n)
  ! if the condition is met
  ! do all the stuff
  ! set the new value of n
  ! set i to 1 to restart the loop
end do
i=1

do while(请显示您的代码如果您事先不知道迭代的确切次数,您可能首先不应该使用带有索引的do循环。