Forum: Offtopic Also wird dann jetzt immer getanzt?


von Micha W. (blackxiiv)


Lesenswert?

1
int song;
2
int dance;
3
void loop() {
4
if (song = 1) {
5
dance = 1;
6
}
7
song = 1;
8
}

Kann das so? :P

von R. M. (Gast)


Lesenswert?

Das Du die Funktion "loop" genannt hast, ändert Nichts daran, das sie 
nur einmal abgearbeitet wird.
mfG

von Claus M. (energy)


Lesenswert?

R. M. schrieb:
> Das Du die Funktion "loop" genannt hast, ändert Nichts daran, das sie
> nur einmal abgearbeitet wird.
> mfG

Nach dem ersten Abarbeiten ist "dance" aber 1.

von Rufus Τ. F. (rufus) Benutzerseite


Lesenswert?

R. M. schrieb:
> Das Du die Funktion "loop" genannt hast, ändert Nichts daran, das sie
> nur einmal abgearbeitet wird.

Nicht in der Arduino-Umgebung.

von Thomas E. (thomase)


Lesenswert?

Micha W. schrieb:
> int song;
> int dance;
> void loop() {
> if (song = 1) {
> dance = 1;
> }
> song = 1;
> }
>
> Kann das so? :P

Erstmal ist das miserabel eingerückt.
1
int song;
2
int dance;
3
4
void loop()
5
{
6
  if(song = 1)
7
  {
8
    dance = 1;
9
  }
10
  song = 1;
11
}

Zudem ist die Variable song überflüssig.
1
int dance;
2
void loop()
3
{
4
  dance = 1;
5
}

Da dance nur auf 1 gesetzt wird, kann man sich auch sparen, das in der 
loop zu tun.
1
int dance = 1;
2
void loop()
3
{
4
5
}

Da das Programm nur aus der loop besteht und in der loop nichts gemacht 
wird, braucht man überhaupt keine Variablen.
1
void loop()
2
{
3
4
}


Da das Programm nichts macht, kann man sich das ganz schenken.

Micha W. schrieb:
> Kann das so?

Nein, das gibt nur Mecker vom Compiler wegen

1
if (song = 1)
2
{
3
  //...
4
}
5
6
warning: suggest parantheses...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.