C - Statement Blocks

A block is a sequence of statements enclosed in braces { ... }. Blocks create scopes and group logic.

Learning Objectives

  • Write and recognize block statements.
  • Understand where blocks are used (functions, conditionals, loops).

Examples

// Function 
int add(int a, int b) 
{
   return a + b;
}

// if block
if (a > b) 
{
  printf("A is greater\n");
} 
else 
{
  printf("B is greater\n");
}

// Iteration 
for (int index = 0; index < 5; index++)
{
  printf("%d\n", index);
}