Lesson 5 of 23

if, else மற்றும் else ifif, else and else if

8 min 25 XP

if ஒரு condition true ஆனால் மட்டும் code-ஐ இயக்கும். பல வழிகளுக்கு else if, மற்ற எல்லாவற்றுக்கும் else. C-ல் 0 என்றால் false, 0 அல்லாத எந்த எண்ணும் true.

if runs code only when its condition is true. Use else if for more choices and else for everything else. In C, 0 means false and any non-zero value means true.

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

if (x = 5) என்று எழுதினால் x-ல் 5 சேமிக்கப்பட்டு எப்போதும் true ஆகும்! ஒப்பிட == பயன்படுத்துங்கள்.

if (x = 5) stores 5 in x and is always true! Use == to compare. This bug is a classic C trap.

Challenge

+25 XP

ஒரு எண்ணைப் படித்து, அது positive என்றால் "Positive", negative என்றால் "Negative", 0 என்றால் "Zero" என்று print செய்யுங்கள்.

Read a number. Print "Positive", "Negative" or "Zero".

Output Loading C (first time takes a few seconds)
Press Run to see the result here.