Eine While Schleife wird verwendet um Code nicht nur Code auszuführen wenn eine Bedingung erfüllt wird sondern er wird so lange ausgeführt bis die Bedingung nicht mehr erfüllt wird.
While-Schleife
JavaScript
let count = 0;
while (count < 5) {
console.log("Count:", count);
count++;
}
Python
count = 0
while count < 5:
print("Count:", count)
count += 1
Rust
fn main() {
let mut count = 0;
while count < 5 {
println!("Count: {}", count);
count += 1;
}
}
C & C++
int main() {
int zahl = 0;
while (zahl < 5) {
printf("Zahl ist %d\n", zahl);
zahl++;
}
}
Dart
void main() {
int count = 0;
while (count < 5) {
print('Wert: $count');
count++;
}
}
PHP
$count = 0;
while ($count < 5) {
echo "Count: " . $count . "\n";
$count++;
}