0
i don't understand this: for example : a=4 while a=4 print (a) a = a + 1 help me please! !!!!
6 Answers
+ 2
while you a = 4
programme print a
before this code a = a + 1
it's mean a = 4 + 1
before this program finished because a > 4
0
thank you very much
0
a = 4 //assigns 4 to the variable a
while a==4 //loop while a is equal to 4
print(a) //print the value of a
a = a + 1 //increments a by 1
You declare a variable a equals to 4. a is equal to 4, so you enter the loop. Inside the loop, you print the value of a (which is 4) and increments a by 1 (a is now 5). The loop goes back to the beginning. a is not equal to 4 anymore, so the loop ends.
0
thank youš
0
The General Form:
iterator = initial_value
while condition_on_the_iterator:
do whatever here
update the value of the iterator
increment/decrement
Evaluates as follows:
1- Checks to see if the condition is True
- If yes the body gets executed
at the end update the iterator and go to 1
- If not (at any iteration), then pass the loop
0
Note:
= is used when assigning a value to a varible
== is used to compare for equality
In any if condition you must use == not = otherwise your program will raise a syntax error