Top Menu

Jump to content
Home
    • Projects
    • Work packages
    • News
    • Getting started
    • Introduction video
      Welcome to OpenProject
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Professional support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Create a new account
      Forgot your password?

Side Menu

  • Overview
  • News
  • Forums
  • Wiki
    • Table of contents
      • Expanded. Click to collapseCollapsed. Click to showWiki
        • Expanded. Click to collapseCollapsed. Click to showBeispielprojekte
          • Hierarchy leafFlappy Box2D
          • Hierarchy leafFlappy Improved
          • Hierarchy leafHighscore Hibernate
          • Hierarchy leafHighscore Webservice + Anbindung mit Retrofit
        • Expanded. Click to collapseCollapsed. Click to showEntwicklung mit Java
          • Hierarchy leaf001) Grundlagen - Entwicklungsumgebung
          • Hierarchy leaf002) Erstes Programm
          • Hierarchy leaf003) Variablen und Datentypen
          • Expanded. Click to collapseCollapsed. Click to show004) Schleifen
            • Hierarchy leaf1) for - Zählschleife
            • Hierarchy leaf2) while
            • Hierarchy leaf3) do while
            • Hierarchy leaf4) for each
          • Hierarchy leaf005) Arrays
          • Hierarchy leaf006) Methoden
          • Expanded. Click to collapseCollapsed. Click to show007) Objektorientierte Programmierung
            • Hierarchy leaf001) Klasse
            • Hierarchy leaf002) Vererbung und Darstellung von Klassen in UML
            • Hierarchy leaf003) Abstrakte Klasse
            • Hierarchy leaf004) Design patterns
          • Expanded. Click to collapseCollapsed. Click to show008) Webservices
            • Hierarchy leaf01) REST - Representational State Transfer
            • Hierarchy leaf02) Minimaler Webservice
            • Hierarchy leaf03) Joke Webservice
            • Hierarchy leaf04) Highscore Service
        • Expanded. Click to collapseCollapsed. Click to showMatura - Vorbereitung
          • Hierarchy leaf01) Projektmanagement
          • Hierarchy leaf02) Objektorientierte Programmierung
          • Hierarchy leaf03) Modellierung und UML
          • Expanded. Click to collapseCollapsed. Click to show04) Design Patterns
            • Hierarchy leaf00) Generelle Konzepte
            • Hierarchy leafFactory(-Method) Pattern
            • Hierarchy leafObserver Pattern
            • Hierarchy leafSingleton Pattern
            • Hierarchy leafStrategy Pattern
          • Hierarchy leaf05) Algorithmen und Datenstrukturen
          • Hierarchy leaf06) Webtechnologien
          • Hierarchy leaf07) Webservices
          • Hierarchy leaf08) Softwarequalitätsmanagement
          • Hierarchy leaf09) Softwareentwicklungsmodelle
        • Expanded. Click to collapseCollapsed. Click to showProjekt Rahmenbedingungen
          • Expanded. Click to collapseCollapsed. Click to showRetrospektive
            • Hierarchy leafRetro - [Name Schüler_in]
        • Hierarchy leafReact Native
        • Expanded. Click to collapseCollapsed. Click to showÜbungen
          • Hierarchy leaf1) Basic
          • Expanded. Click to collapseCollapsed. Click to show2) Basic
            • Hierarchy leaf001) Methode ohne Rückabewert mit Parametern
            • Hierarchy leaf002) Methode mit Parametern und Rückgabewert
            • Hierarchy leaf003) Text umdrehen
            • Hierarchy leaf004) Text umdrehen 2
            • Hierarchy leaf005) Kommandozeile
            • Hierarchy leaf006) Kommandozeile 2
            • Hierarchy leaf007) Vererbung - Geometry
            • Hierarchy leaf008) File from String
            • Hierarchy leaf009) Rekursion - Summe
            • Hierarchy leaf010) Rekursion - File
          • Expanded. Click to collapseCollapsed. Click to showDatenstrukturen
            • Hierarchy leaf011) Binärbaum
            • Hierarchy leaf012) Binärbaum - Generics
            • Hierarchy leaf013) AVL - Tree
            • Hierarchy leaf014) Linked List - Einfach verkettete Liste
            • Hierarchy leaf015) Graph
            • Hierarchy leaf016) Dijkstras shortest path first
          • Expanded. Click to collapseCollapsed. Click to showJava - Kara
            • Hierarchy leafKara lernt schreiben
You are here:
  • Wiki
  • Entwicklung mit Java
  • 004) Schleifen
  • 2) while

Content

2) while

  • More
    • Print
    • Table of contents
  • Im Gegensatz zur for Schleife besteht die while Schleife nur aus einer Bedingungsprüfung und dem Schleifenrumpf
  • Der Schleifenrumpf wird solange die Bedingungsprüfung wahr (true) ist ausgeführt
  • Die Bedingung kann auch ein unveränderlicher Wert z.b.: true

Bsp 1)

while(true) {
    System.out.println("Hallo");
}

...gültige Endlosschleife

Bsp 2)

int a = 0;
while(a < 10) {
    System.out.println(a);
    a++;
}

...gibt die Zahlen von 0 bis 9 aus

Bsp 3)

Eine for Schleife kann auch immer als while Schleife ausgedrückt werden. Es werden nur um einiges mehr Zeilen Code benötigt.

for (int i = 11; i < 15; i = i + 2) {
    System.out.println("Programmieren macht Spaß!");
}

...die Zählvariable startet bei 11 und läuft bis kleiner 15 in 2er Schritten. Ausgabe erfolgt 2 mal.

int i = 11;
while (i < 15) { 
    System.out.println("Programmieren macht Spaß!");
    i = i + 2;
}

...selbes Beispiel als while Schleife

int i = 11;
while (true) {
	if(i>=15) {
        break;
    }
    System.out.println("Programmieren macht Spaß!");
    i = i + 2;
}

...erneut selbes Beispiel, die Bedingungsprüfung ist hier jedoch immer wahr (true). Die Schleife wird durch das Schlüsselwort break beendet.

Es wird hier nicht mehr nach i < 15 geprüft, sondern die Prüfung umgedrecht: i >= 15

Loading...