{"id":194,"date":"2012-06-24T21:46:15","date_gmt":"2012-06-24T19:46:15","guid":{"rendered":"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=194"},"modified":"2012-06-24T21:55:36","modified_gmt":"2012-06-24T19:55:36","slug":"kontrollstrukturen","status":"publish","type":"page","link":"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=194","title":{"rendered":"Kontrollstrukturen"},"content":{"rendered":"<p>Es gibt auch in Inform 7 die \u00fcblichen Kontrollstrukturen: <strong>if-then-else, while, Z\u00e4hlschleife, switch.<\/strong> In Java kann eine solche Kontrollstruktur nicht irgendwo im Code erscheinen, sondern nur innerhalb von Methoden. Das gleiche gilt auch f\u00fcr Inform: Kontrollstrukturen stehen innerhalb von Methoden oder Regeln.<\/p>\n<h3>Beispiel: While<\/h3>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">To count down:\r\n\tlet x be ten;\r\n\twhile x is at least zero:\r\n\t\tsay x;\r\n\t        decrease x by one.\r\n<\/pre>\n<p>Nach <code>while<\/code> steht wie immer jede Aussage, die als boolescher Wert evaluiert wird.<\/p>\n<p>Dabei benutzt Inform statt der geschweiften Klammern von Java die Einr\u00fcckung durch Tabulatoren wie in Python. Es gibt auch eine Schreibweise mit expliziter <code>begin<\/code>-Markierung, aber die ist unsch\u00f6n.<\/p>\n<p>&#8212; Methoden in Inform unterscheiden sich sprachlich leicht voneinander, beginnen aber alle mit dem Wort <strong>to<\/strong>. Beispiele:<\/p>\n<ul>\n<li>Kopf einer Prozedur ohne R\u00fcckgabewert und ohne Argument:<br \/>\n<code>To count down:<\/code><\/li>\n<li>Kopf einer Methode mit booleschem R\u00fcckgabewert und einem Zahl-Argument:<br \/>\n<code>To decide whether (x - a number) is big:<\/code><\/li>\n<li>Kopf einer Methode mit R\u00fcckgabewert von anderem Typ (hier einer Zahl), und einem Zahl-Argument:<br \/>\n<code>To decide what number is the square of (x - a number):<\/code><\/li>\n<\/ul>\n<p>Allerdings braucht man diese Methoden &#8211; siehe eigenes Kapitel dazu &#8211; in Inform weniger oft. H\u00e4ufiger trifft man Kontrollstrukturen innerhalb von Regeln, deshalb beschr\u00e4nken sich die folgenden Beispiele auf diese. Methoden werden immer dann ausgef\u00fchrt, wenn sie im Programmcode explizit aufgerufen werden; Regeln werden dagegen w\u00e4hrend des Spielzug-Zyklus vom Programm immer wieder zu festgelegten Zeiten auf ihr Zutreffen \u00fcberpr\u00fcft und befolgt.<\/p>\n<h3>Beispiel: If-then-else<\/h3>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">Instead of going west from the Entrance Area:\r\n\tIf the player is wearing the white hoodie:\r\n\t\tIf the voice of the player is low:\r\n\t\t\tSay &quot;You can't go through there. From inside, you hear voices shouting: 'No, you don't sound like our mother.'&quot;; \r\n\t\tOtherwise:\r\n\t\t\tContinue the action;\r\n\tOtherwise:\r\n\t\tSay &quot;You can't go through there. From inside, you hear voices shouting: 'No, you're not our mother. Our mother has got white hair.'&quot;\r\n<\/pre>\n<p><code>Otherwise if<\/code> geht nat\u00fcrlich auch. <\/p>\n<h3>Beispiel: Z\u00e4hlschleife<\/h3>\n<p>Es gibt einfache Z\u00e4hlschleifen:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">After eating the apple:\r\n\trepeat with x running from 1 to 10:\r\n\t\tsay x;\r\n\t\tsay line break;\r\n\tsay &quot;Burp.&quot; \r\n<\/pre>\n<p>Dabei wird die Z\u00e4hlvariable bei jedem Durchgang um 1 erh\u00f6ht, eine andere M\u00f6glichkeit gibt es leider nicht direkt.<\/p>\n<p>Viel h\u00e4ufiger verwendet man diese Struktur, um eine Aufz\u00e4hlung oder Liste von Objekten durchzugehen:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">repeat with x running through open containers: \r\nrepeat with x running through things carried by the player:\r\nrepeat with x running through all books: \r\n<\/pre>\n<p>Da entspricht in Java: <code>for (Element e : collection)<br \/>\n<\/code>.<\/p>\n<h3>Beispiel: Switch<\/h3>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">Every turn:\r\n\tlet x be a random number between 1 and 6; \r\n\tif x is:\r\n\t\t-- 1: say &quot;You hear thunder in the distance.&quot;; \r\n\t\t-- 2: say &quot;A bolt of lightning flashes somewhere far away.&quot;; \r\n\t\t-- otherwise: say &quot;Nothing happens.&quot;\r\n<\/pre>\n<p>Dabei kann eine Variable von beliebigem Datentyp (auch Referenzdatentyp) hergenommen werden:<\/p>\n<pre class=\"brush: inform7; title: ; notranslate\" title=\"\">Every turn:\r\n\tlet x be a random thing carried by the player; \r\n\tif x is:\r\n\t\t-- the apple:\r\n\t\t\tsay &quot;You play around with the apple, then put it away again.&quot;;\r\n\t\t-- the coin:\r\n\t\t\tsay &quot;You toss the coin aimlessly for a while.&quot;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Es gibt auch in Inform 7 die \u00fcblichen Kontrollstrukturen: if-then-else, while, Z\u00e4hlschleife, switch. In Java kann eine solche Kontrollstruktur nicht irgendwo im Code erscheinen, sondern nur innerhalb von Methoden. Das gleiche gilt auch f\u00fcr Inform: Kontrollstrukturen stehen innerhalb von Methoden &hellip; <a href=\"https:\/\/herr-rau.de\/blogs\/inform\/?page_id=194\">Weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":94,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-194","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=194"}],"version-history":[{"count":0,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/194\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=\/wp\/v2\/pages\/94"}],"wp:attachment":[{"href":"https:\/\/herr-rau.de\/blogs\/inform\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}