#include <iostream>
using namespace std;
int main() {
int n = 8, n2 = n;
// mit Post-Dekrement
n2 = n;
while (n2--){
cout << n2;
cout << '*';
}
cout << endl;
// mit Pre-Dekrement
n2 = n;
while (--n2) {
cout << n2;
cout << '*';
}
cout << endl;
return 0;
}
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
// klappt auch beim Array:
int a[] {1,2,3,4};
for (int i : a){
cout << i << " ";
}
cout << endl;
string s {"Dortmund"};
for (int c: s) { // <-- probiert hier mal einen anderen Datentyp aus
cout << c << " ";
}
cout << endl;
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
float x;
int i = 0;
for (x = 0.4; x != 10.4; x++, i++){
// cout << "i = " << i << ", x = " << x << endl;
// Eine Endlosschleife verhindern.
// Bei irgendwas größer 11 brechen wir zur Sicherheit ab.
if (x > 11) {
break;
}
}
cout << "Ende" << endl;
cout << "i = " << i << ", x = " << x << endl;
return 0;
}
for (Initialisierung; Bedingung; Veränderung)
#include <iostream>
using namespace std;
int main() {
// Deklaration von s vor der Schleife, damit
// s nach der Schleife noch sichtbar ist
int s;
// for-Schleife ohne Bedingung!
for (s = 0; ; ++s){
cout << s << endl;
if (s % 17 == 0 && s > 1000){
cout << "break" << endl;
break;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "Programm weiter ausführen? (j)a, (n)ein" << endl;
char c = 'J';
//cin >> c;
if (c == 'j' || c == 'J'){
cout << "Programm wird weiter ausgeführt" << endl;
} else {
if (c == 'n' || c == 'N'){
cout << "Programm wird beendet" << endl;
} else {
cout << "Falsche Eingabe!" << endl;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
cout << "Programm weiter ausführen? (j)a, (n)ein" << endl;
char c = 'J';
//cin >> c;
// ohne Klammerung
if (c == 'j' || c == 'J')
cout << "Programm wird weiter ausgeführt" << endl;
else if (c == 'n' || c == 'N')
cout << "Programm wird beendet" << endl;
else cout << "Falsche Eingabe!" << endl;
return 0;
}