+ 1
What is the difference between an "if" loop and "while" loop!
I started the lesson in while loops confident, but when I started learning I could not tell the difference for what if loops does, and while loops
3 Réponses
+ 3
The difference between for and while loops is only in syntax.
In for loop you initialize your variable(s), that take part in condition, set the condition and define variable(s) changes after executing loop's body. Everything above is in parenthesis of for statement.
In while loop you do exactly the same, but in different places. You can define those variables before loop, set condition in parenthesis of while statement and change those variables at the end of loop's body (or anywhere you need).
Pointing out the difference, variables initialized via for statement won't exist outside the loop. But the same can be reached via while loop in some specific way
+ 1
if statement doesn't create loop. It only checks condition and executes code block if it is true, only one time.
while statement creates a loop. It also checks condition and executes code block after it if it is true, multiple times, until condition becomes false
0
microBIG My Apologies for the misleading question I meant to ask the difference to a for loop and while loop