0
I don't understand this loops thing
10 Respuestas
0
+=
-=
*=
/=
%=
Are shorthands for x = x + x
x = 0;
x += 5 means x = x + 5; result: 5
x -= 5 means x = x - 5; result: -5
x *= 5 means x = x * 5; result 0
Etc
In your case, x+= 2 means
x = x + 2
+ 5
Which part exactly?
+ 5
while loops repeat the code inside their bodies until their condition fails. Meaning that the thing inside their brackets becomes false. In most languages, 0 evaluates to false and all other numbers to true.
Is there any specific sample in the tutorial that confused you perhaps?
0
Everything about the while loops
0
i = 1
while i <=5:
print(i)
i = i + 1
print("Finished!")
Why does it print
1
2
3
4
5
Finished!
0
While will repeat the code as long as the condition is true
Today is sunny, while its sunny, go outside
If it starts raining, get back inside
bool weather = sunny;
While (sunny)
{ go outside }
You also need a condition so you're not stuck in endless sunny days - it's usually sunny for 5 days sooo
int days = 0;
while (sunny && days <5 )
{ go outside
days++ (this will add a new day after the code runs)
}
On the fourth day, variable "days" will hit 5 and you will go back inside
0
Loop executes 5 times and runs the print command
After its done looping, it prints out finish
0
Ok, thanks alot.
I understand now.
Very easy
0
Pls can you explain the x+=2
0
Amazing 😍👌. You too good . thanks again