{"id":121,"date":"2017-09-13T10:17:20","date_gmt":"2017-09-13T13:17:20","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=121"},"modified":"2017-09-13T10:17:20","modified_gmt":"2017-09-13T13:17:20","slug":"iftests-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/iftests-f\/","title":{"rendered":"iftests.f"},"content":{"rendered":"<pre>c &lt;html&gt;\r\nc &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt;\r\nc &lt;body&gt;\r\nc &lt;pre&gt;\r\nc\r\nc\r\nc       John Mahaffy,  Penn State University, CmpSc 201 Example\r\nc       1\/26\/96\r\nc\r\n      program iftests\r\n      implicit none\r\nc&lt;a name=\"logical\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      logical ltest\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n      integer i,j\r\n      character*1 char\r\nc\r\nc    This program gives examples of various uses of the if statement\r\nc\r\nc    variables:\r\nc      i -  an input integer\r\nc      j -  an integer used in some tests\r\nc      char -  an input single character\r\nc      ltest - logical variable holding the results of a comparison\r\nc\r\nc    Begin by reading in a integer\r\nc\r\n  10  print *, 'Type in an integer value:'\r\nc\r\n      read *, i\r\nc\r\nc     The arithmetic IF statement is archaic.  You shouldn't use it\r\nc     but need to know that it exists.\r\nc\r\nc&lt;a name=\"a1\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      if(i-100) 20,30,40\r\n   20 print *, 'input is less than 100'\r\n      go to 50\r\n   30 print *, 'input is equal to 100'\r\n      go to 50\r\n   40 print *, 'input is greater than 100'\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\nc\r\nc     The simplest logical IF just does something immediately\r\nc\r\n 50   if(i.lt.0) i=-i\r\n      if(i.gt.50.and.i.lt.100) print *, ' 50 &lt; input &lt; 100 '\r\nc\r\nc    A more powerful logical IF conditionally executes a block of code\r\nc    the word 'then' always appears at the end of the IF line and the\r\nc    block of code is ended with a line saying 'endif' or 'end if'\r\nc    Note the use of indentation to highlight the structure.\r\nc\r\n      if(i.ge.100.and.i.le.200) then\r\n         i=i+150\r\n         print *, 'i incremented by 150'\r\nc&lt;a name=\"14\"&gt;&lt;font color=\"00FF00\"&gt;\r\n      endif\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc    The contents of the parentheses can always be replaced by a logical\r\nc    variable\r\nc\r\n      ltest= i.ge.-200.and.i.le.-100\r\n      if (ltest) then\r\n         i=i+200\r\n         print *, 'i incremented by 200'\r\n      endif\r\nc\r\nc    Block logical IF's may contain other tests and a final option\r\nc    (ELSE) to be executed if one of the others is not done.  Only one\r\nc    of the possible actions will be taken.  When it is the others are\r\nc    bypassed\r\nc&lt;a name=\"10\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      if((i.gt.200.and.i.le.300).or.(i.gt.1200)) then\r\n         i=i+200\r\n         print *, 'input incremented by 200'\r\n      else if (i.eq.400) then\r\n         print *, 'input = 400'\r\n      else\r\n         print *, 'Nothing special about input.'\r\n      endif\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\nc\r\nc    Sometimes it makes sense to use the Fortran 90 Case structure instead\r\nc    of IF, ELSE IF structures.  Only one case will be done\r\nc\r\nc&lt;a name=\"case\"&gt;&lt;font color=\"FF0000\"&gt; \r\n      select case (i)\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\n         case default\r\n            print *, 'Nothing special about input.'\r\n         case (201:300)\r\n            i=i+200\r\n            print *, 'input incremented by 100'\r\n         case (400)\r\n            print *, 'input = 400'\r\n      end select\r\nc\r\nc    Of the above examples only SELECT CASE required use of an integer\r\nc    rather than a real number. However SELECT CASE also functions with\r\nc    Character strings.\r\nc\r\n      print *, 'Do you want to continue? (y or n)'\r\n      read 1000, char\r\n1000  format(a1)\r\n      select case (char)\r\n         case ('y')\r\n            ltest=.true.\r\n            print *, 'Continuing'\r\n         case ('n')\r\n            ltest=.false.\r\n            print *, 'Stopping'\r\n         case default\r\n            print *, 'Incorrect Response'\r\n            stop\r\nc&lt;a name=\"es\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      end select\r\nc&lt;\/a&gt;&lt;\/font&gt;\r\nc    The most basic if test (what the machine does) is just a branch\r\nc    These things make the flow of the program difficult to follow and\r\nc    should be used as little as possible\r\nc\r\n      if(ltest) go to 10\r\nc\r\nc    An if test that forces a loop through coding can be implented in\r\nc    Fortran 90 with a DO WHILE structure.  Notice values of i and j\r\nc    when the loop is done.  The test always done at the beginning of\r\nc    the loop.\r\nc\r\n      i=0\r\n      j=2\r\nc&lt;a name=\"dow\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      do while (i.lt.10.and.j.lt.10000)\r\nc&lt;\/font&gt;&lt;\/a&gt;\r\n         i=i+1\r\n         j=j**2\r\n      end do\r\n      print *, 'i = ',i,' , j = ',j\r\nc\r\n      stop\r\n      end\r\nc\r\nc &lt;\/pre&gt;\r\nc &lt;\/body&gt;\r\nc &lt;\/html&gt;\r\nc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c &lt;html&gt; c &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt; c &lt;body&gt; c &lt;pre&gt; c c c John Mahaffy, Penn State University, CmpSc 201 Example c 1\/26\/96 c program iftests implicit none c&lt;a name=&#8221;logical&#8221;&gt;&lt;font color=&#8221;FF0000&#8243;&gt; logical ltest c&lt;\/font&gt;&lt;\/a&gt; integer i,j character*1 char c c This program gives examples of various uses of the if statement c c variables: c i &#8211; [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-121","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/121\/revisions"}],"predecessor-version":[{"id":122,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/121\/revisions\/122"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}