Tsallaka zuwa abun ciki
Justice Tech School

if, else if and else

Any non zero value is true. Use braces to avoid mistakes.

Example
#include <stdio.h>

int main(void) {
  int n = 15;
  if (n % 15 == 0) printf("FizzBuzz\n");
  else if (n % 3 == 0) printf("Fizz\n");
  else printf("%d\n", n);
  return 0;
}

Result

FizzBuzz

Exercise

Else branch.

if (x) {}  {}

Quiz Test

What counts as true in C?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.