+ 14
Where difference between loop and if statement using for loop
Can please write code please
6 odpowiedzi
+ 7
An if statement checks if an expression is true or false, and then runs the code inside the statement only if it is true. The code inside the loop is only run once...
or it continues to execute the code however long the expression is true.
+ 3
If statements are to implement choice. Loops are to implement repetitions.
+ 1
Statements in an if structure, should not loop or be performed more than once. Statements in a Loop structure repeat until a condition is met
+ 1
An if statement checks its condition once, but a loop can possibly check its conditional many times.
int num = 100;
if ( num > 5 )
{
//The conditional num>5
// is checked exactly once
}
while ( num < 103 )
{
num++; //add 1 to num
//The conditional num <=105
// is checked 4 times—
// when num = 100, 101, 102
// and 103. The while block
// won’t run when num = 103
}
while ( num > 1 )
{
num = num + 1;
num = num - 1;
//An infinite loop
}
for ( int i = 0; i < 10; i++ )
{
//The conditional i < 10 is
// checked 10 times.
}
- 1
hello add egg to waffles