Fortran coding do loop

luvbite38

Active Member
Joined
Jun 25, 2008
Messages
368
Can some1 kindly help me understand the following code, I am trying to translate the following code in VBA:

Thanks in advance

FFLC = FLC .......i understand this part
ANGLE=PI/6 !Suppose 30 Degrees .......i understand this part
Do 21800 I=i,5 .......Don't understand this
FLC=FFLC-COS(ANGLE)*NDIA
FLE=SQRT(FLB*FLB+FLC*FLC) .......i understand this part
21800 ANGLE=ATAN2(FLC,FLB).......i understand this part
if (R.NE.o.)D=R/2.+NDIA/2.......i understand this part
FLCUT = ........ .......i understand this part
LE=IFIX(FLE).......Don't understand this

My answer for FLCUT is 2387 when using the 30 degree angle but fortran result 2397 (after using the iteration which I dont understand)

Can someone please help me understand this please?

Regards
<!-- google_ad_section_end --><!-- / message -->
 
Example of a Do loop in Fortran

Do 10 I = 1 to 10
J=J+I
10 CONTINUE

Equivalent VBA

For i = 1 to 10
j=j+i
Loop
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi mate,

I hope it will be the last question of this thread.

how we got N = 50 in first example and N = 0 in the second.

Example1

N = 0
Do 100 I = 1,10
J = I

Do 100 K = 1,5
L=K

100 N = N+1
101 Continue

Example 2

N = 0
Do 200=I=1,10
J=I
Do 200 K=5,1
L=K
200 N=N+1
201 Continue

I am totally new to VB and fortran and trying to understnad how the loops or in other words iterative cals work using the Do in fortran.

Apology for any trouble
 
Upvote 0
forgot to mention, the answers (N=50 and 0 for Ex1 and 2 respectively) were supplied in one of the axample I have found online.
 
Upvote 0
In your second example you need to include the increment

Do 200 K=5,1,-1

Equivalent to VBA

For k = 5 to 1 Step -1
 
Upvote 0
:'( there is no increment included in online example.... and where's N=50 came from in eX 1.... trust me I am not even very good at VBA..... could you kindly explain me like you explain it to dumest person on the planet eart :(
 
Upvote 0
By default a DO statement expects the increment to be 1. So

Do 200 K=1,5

loops 1, 2,...5.

Do 200 K=5,1

does not loop at all since 5 is greater than 1. To make it loop backwards you need to supply the increment (-1)

Do 200 K=5,1,-1
 
Upvote 0
The two loops in your second example need a step size (-1) in them (otherwise it is assumed to be 1 and your loop will not execute).

The general format looks like

Do LABEL Variable=Start,End,Step

Code
Code

LABEL

If you nest loops with the same end label then it executes them so it does the last loop you start first (the "inside loop") and when it completes that it goes out one step and increments the outside loop which then runs through the inside loop again from the start and so on.
 
Upvote 0
By default a DO statement expects the increment to be 1. So

Do 200 K=1,5

loops 1, 2,...5.

Do 200 K=5,1

does not loop at all since 5 is greater than 1. To make it loop backwards you need to supply the increment (-1)

Do 200 K=5,1,-1
Thanks Alot..... A million Zillion thanks for your assistance VoG
 
Upvote 0

Similar threads

Forum statistics

Threads
1,223,954
Messages
6,175,600
Members
452,658
Latest member
GStorm

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top