0

Is there a similarity between if and while loop?

2nd Feb 2017, 1:15 PM
Gagan Kumar
Gagan Kumar - avatar
3 Answers
+ 1
yea, the both are conditional, its mean only works when the requirements is true... but if statement look more static (usually perform 1 time operation) and while statement just looping the operation if the requirement is still true but the both still need the conditional event or bool to perform task
2nd Feb 2017, 1:28 PM
Elvin Auresius
Elvin Auresius - avatar
0
There is not only a similarity, they are the samething with a different syntax. Every while-loop can be transformes into a for-loop and vice versa. There are even languages (for example the popular language Swift) that removed the for-loop since every case can be handled using while.
2nd Feb 2017, 1:59 PM
~datell
0
If and while are similar in the sense that they both check if a condition is true and then execute the statements. The If statement checks the condition and does the operation once, whereas While statement keeps executing the operations as long as the condition is true
2nd Feb 2017, 2:23 PM
Nimisha
Nimisha - avatar