12 doloops

50 %
50 %
Information about 12 doloops

Published on March 9, 2014

Author: fyjordan9

Source: slideshare.net

Basic Scientific Programming Do Loops (Cont.)

Loops Controlled by a Logical Expression   In the previous class we talked about loops controlled by a counter in which the number of iterations is known in advance. What if the number of iterations cannot be determined in advance?? Use loops controlled by a logical expressiosn

Loops Controlled by a Logical Expression    General form Do Statement-Sequence 1 If (logical expression) exit Statement-Sequence 2 End Do Either stat-seq1 or stat-seq2 may be omitted. The statements that make up the body of the loop are executed repeatedly until the logical expression in the if statement becomes true.

Ex.  Sum = 0 i=0 do If(i>5) exit sum = sum + I print*, i i=i+1 End Do Output 0 1 2 3 4 5

Ex.  Sum = 0 i=0 Do print*, I If(I>5) exit sum = sum + i I=I+1 End do Output 0 1 2 3 4 5 6

Notes   It is important to initialize the variables used in the logical expression before entering the loop. If the logical expression never becomes true, an infinite loop will result. Ex. J=1 do if( J>9) exit print*, J end do ! Infinite loop.

Input Loops  One common use of loops is to read and process data. Because it is not possible to determine in advance how many data values are to be used, a general loop should be used. ex: do read*, name …… print*, ‘ do you want to quit?’ read*, ch if((ch==‘Y’) .or. (ch==‘y’)) exit end do

Using loops to verify input range  Do Do print*, ‘enter a positive number’ read*, num if( num >= 0) exit end do Do I=0, num print*, num end do print*, ‘ do you want to quit?’ read*, ch if((ch==‘Y’) .or. (ch==‘y’)) exit end do

Named Do Loops  We can attach a label at the beginning and end of the construct. This is useful in the case of nested loops. Ex outer: Do m=1,4 inner: Do n = 1,4 print*, n*m end do inner end do outer

Example input : do print*,”enter two numbers” read*, num1,num2 do I = num1,num2 if(I**3+2*I*I-13*I+10 == 0) then print*, ‘you found one root’, I exit input end do print*, ‘no root between’,num1,’ ‘,num2 print*, ‘ do you want to try againg?’ read*, ch If((ch==‘N’) .or. (ch==‘n’)) exit end do input

The DO-CYCLE Construct  Sometimes it is necessary to terminate only the current repetition and jump ahead to the next one. We use the cycle statement for this purpose.

Example  Do j =1,30 I = (j+15)/(j-10) print*, I End Do something is wrong!! Run time error.  Do j =1,30 if (j==10) Cycle I = (j+15)/(j-10) print*, I End Do

Add a comment

Related presentations

Related pages

doloops Spiele - Cornhole, XXL Spiele, Outdoorspiele

Das ganze Team von doloops-Spiele wünscht dir eine actionreiche Zeit. Nicht das passende gefunden, ... Geistes Blitz 5 vor 12 - Neue Edition 2013.
Read more

Industrie | doloops

Explore OMV zeigt in drei Phasen, wie die Welt der OMV sich über die Jahre verändert hat.
Read more

Suchergebnis auf Amazon.de für: doloops: Spielzeug

21 Ergebnisse für Spielzeug: "doloops" "doloops" Abbrechen. Noris Spiele 606101281 - Castro ... 8 - 11 Jahre (12) Beliebige Kategorie; Spielzeug; Spiele (10)
Read more

doloops (@doloops) | Twitter

The latest Tweets from doloops (@doloops). erquickenderes Team mit ordentlich Potential für kreative, browserbasierende Applikationen aller Art. Wien ...
Read more

Test ATK Raider 12 | Bergsteigen.com

Wir haben uns auf dem immer größer werdenen Markt der Pinbindungen umgeschaut und sind auf die Raider 12 von ... doloops. Klettersteigführer ...
Read more

Wasserpistole Gamma Action - Toy Story Edition - doloops ...

Der spritzige Spaß für die warmen Tage oder das Hallenbad. Holt Euch die super Toy Story Wasserpistole.
Read more

PartII% DOLoops

DOLoops%% DO#loops#allow#blocks#of#commands#to#be#repeated. # General#form#of#DO#loops: DO # = , ... ↵ = 12 Xn j=1 Xm k=1 (1)j+k p ...
Read more

doloops, Märzstrasse 7, 1150 Wien, Austria | drupical ...

Thursday, 11. July 2013 - 18:00 to Friday, 12. July 2013 - 1:00. 1. Wiener Drupal Wuzzel Turnier #druwuz: User group meeting
Read more

Bergsteigen.com | Das Portal für Klettern, Bergsteigen ...

02.12.2015 - 20:56. ... Implementierung: doloops. Klettersteigführer Dolomiten - Südtirol - Gardasee | Klettersteigführer Österreich ...
Read more