summaryrefslogtreecommitdiffstats
path: root/contents/wissen/cpp-tutorial/06-schleifen.php
blob: 508c106567fe1c71c984f997f53b831795491fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
	$author = 'Jakob und Matthias';
	$pathToRoot = '../../../';
?>
<?php
	include($pathToRoot . 'includes/firstinclude.inc.php');
	include($pathToRoot . 'includes/header.inc.php');
	include($pathToRoot . 'includes/mainmenu.inc.php');
	
	include($pathToRoot . 'sidebars/wissen/cpp.inc.php');
?>

<div id="inhalt";>
	<h2>
		6. Schleifen
	</h2>
	<p>
		<code style="white-space:pre">
#include &lt;iostream&gt;
	
int main()
{
  int iX, iY;
  iX = 0;

  while(iX != 5)
  {
    std::cout &lt;&lt; &quot;Geben sie eine diskordische Zahl ein!&quot; &lt;&lt; std::endl;
    std::cin &gt;&gt; iX;
  }


  for(int i = 0; i < 25; i++)
  {
    std::cout &lt;&lt; &quot;iX * &quot; &lt;&lt; i &lt;&lt; &quot;: &quot; &lt;&lt; i * iX &lt;&lt; std::endl;
  }
  
  return 0;
}
	
		</code>
	</p>
	<p>
Das erste ist eine while-Schleife. Sie wird so lange ausgeführt, wie die Bedingung wahr ist,
in diesem Fall also solange iX ungleich 5 ist.
	</p>
  <p>
Die for-Schleife folgt folgendem Schema:
	</p>
	<p>
for(Variable; Bedingung; Inkrementor)
	</p>
	<p>
Am Anfang wird einmal der Befehl &lt;Variable&gt; ausgeführt, nach jedem Durchlauf wird einmal &lt;Inkrementor&gt;
ausgeführt, und die Schleife läuft, solange die Bedinung wahr ist.
	</p>
<h3>Aufgabe:</h3>
<p>
Erstelle ein Programm, das mit Hilfe einer
Funktion eine beliebige Potenz einer Zahl berechnen kann.
Baue diese Funktion in einen Taschenrechner ein,
der sich nur beendet, wenn der Benutzer es wünscht,
sodass mehrere Rechnungen hintereinander möglich sind.
</p>
<p>
Dies ist der letzte Taschenrechner, versprochen! ;)
</p>
</div>
	
<?php
	include($pathToRoot . 'includes/footer.inc.php');
	include($pathToRoot . 'includes/lastinclude.inc.php');
?>