Question about the break code if statement


#1

Hi Everyone,

Could someone bring me up to speed with the if statement here please? I can’t wrap my head around the (i + 90 == i * i) part of the code, could someone help me understand this part.

Cheers

JP

[code]
#include <stdio.h>

int main (int argc, const char * argv[])
{
int i ;
for (i = 0; i < 12; i++) {
printf(“Checking i = %d\n”, i);
if (i + 90 == i * i) {
break;
}
}
printf(“The answer is %d.\n”, i);
return 0;
}/code]


#2

(i + 90 == i * i) this is the check to see if the loop has found the number that satisfies the question what is the number x such that x+90 = x squared. == is the logical check for is true when the right side of the equation equals the left side of the equation.

I did have a problem running this until I moved the printf command between the if statement and the break statement. then it ran fine.

hope this helps

#include <stdio.h>

int main(int argc, const char * argv[]) {
for (int i=0; i<12; i++)
{
printf(“checking i = %d\n”, i);
if (i + 90 == i * i ) {
printf(“The answer is %d.\n”, i);
break;
}
}

return 0;

}


#3

Hi Imdrev,

Thanks for the reply :slight_smile:

It is funny how the universe works! I was sitting on the train this morning and reviewed the break function and it clicked what the if statement was about haha

if (10 + 90 == 10 * 10)…

It was staring right at me with the output! just needed that “aha” moment