Question I don't understand if statement

RavCoder

Member
Joined
Aug 28, 2019
Messages
5
Programming Experience
Beginner
Hi everyone,
I'm beginner developer in C# ,this is my first post in this forum and I ask to explain this code because I don't understand if statement:
C#:
using System;

public class Program
{
    public static void Main()
    {
        if (144 != 12 * 12) {
            Console.WriteLine("Math isn't in this world, kid!");
        }
        else {
            Console.WriteLine("Surprise, man!");
        }
    }
}
I found this in a course online about C# language ( Codeasy.net).
Thanks and regards,
P.s Sorry for my English, but it's not my first language!!!
 
Last edited by a moderator:
If a condition is not met in if ( [CONDITION] )
else will execute the else { } block of that statement.
You would not do maths inside of a condition. The condition is where you would compare the value or value(s) of one or more item(s).
When you do 12 * 12 inside an if statement, as you've done; you are only performing an operation between the two numbers where a conditional value is expected. This won't work as you are not producing an output for the condition to evaluate. Assign your variable to your maths like so int value = 12 * 12; if (value != 144) and declare your variable and perform your maths operation before your conditional statement runs. See the link in my signature for Conditional Logic IfElse. Expand the spoiler and you will see the links.
 
Thanks!!!
I think It was an exercises to understand if condition and numbers type.
However I will read the link that you send me.
 
Please only write in English on this forum. There are an abundance of translators out there if you need them.

And you're welcome.
 
Back
Top Bottom