• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 67 pages
Presentation

Control Structures and Enumerations

Document preview thumbnail
Preview 4 out of 67 pages

Die BESTE Einführung für Inforamtik für If, while, for und Enumerations

Content preview

Einführung in die Informatik
Control Structures and Enumerations

If, while, for und Enumerations


Wolfram Burgard




7/1

, Motivation

• Bisher bestanden die Rümpfe unserer Methoden aus
einzelnen Statements, z.B. Wertzuweisungen oder
Methodenaufrufen.

• Es gibt bisher keine Möglichkeit, Statements nur in
Abhängigkeit bestimmter Umstände auszuführen.

• Durch bedingte Anweisungen und Schleifen können wir
flexiblere Methoden schreiben und deutlich mächtigere
Modelle entwickeln.




7/2

, Das if-Statement

• Java stellt mit dem if-Statement eine Form der bedingten Anweisung zur
Verfügung.
• Mit Hilfe des if-Statements können wir eine Bedingung testen und, je
nach Ausgang des Tests, eine von zwei Anweisungen durchführen.

if (axles == 2)
tollDue = 4;
else
tollDue = 5 * axles;

• Zeile 1 enthält den Test, den wir ausführen.
• Zeile 2 enthält das Statement, das bei erfolgreichem Test ausgeführt wird.
• Zeile 3 enthält das Schlüsselwort else und läutet den Teil ein, der
ausgeführt wird, wenn der Test fehlschlägt.
• Zeile 4 enthält das Statement, welches bei negativem Ausgang des Tests
ausgeführt wird.
7/3

, Die zwei Formen des if-Statements

• Die erste Variante des if-Statements verzweigt in zwei
unterschiedliche
• Programmstücke, die in Abhängigkeit von dem Test ausgeführt
werden:
if (condition)
statement1
else
statement2
• Die zweite Version lässt den else-Teil aus und führt das Statement
nur aus, wenn der Test erfolgreich ist.
if (condition)
statement
In dieser Version wird das Statement nur ausgeführt, wenn die
Bedingung wahr ist, sonst wird die Anweisung ausgelassen.

7/4

Document information

Study
Realschule
School year
1
Uploaded on
March 19, 2023
Number of pages
67
Written in
2022/2023
Type
Presentation
Person
Unknown
$8.40

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
1
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions