0
What are loops
variable loops
4 Answers
+ 9
a=0
while True:
print("what is a loop? %s"%a)
a+=1
+ 6
Loops are used to support easy repetition of instructions, they are invented to help programmers so they don't have to rewrite or copy & paste blocks of code to repeat the instructions in the block. Theres a chapter in Python tutorial that covers loops, it's in the "Control Structures" chapter.
+ 2
they will repeat code as long as the condition is met
0
while(condition_is_true){
do_this_stuff;
}
or
for(initialiser, condition,inr/dcr){
do_this;
}
or
do{
do_this;
}while(condition);
Use for loop when exact iterations are known directly/indirectly
Else use while or do while depending on situation
(note:while and for loops check condition before entering loop and do while don't hence do while gets executed at least once)