> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/NormandoRamirezDelgado/6C-Febrero-2026/llms.txt
> Use this file to discover all available pages before exploring further.

# Function Basics

> Learn how to create and use basic functions in Dart

## Introduction

Functions are reusable blocks of code that perform specific tasks. In Dart, functions help you organize your code and avoid repetition.

## Basic Function Syntax

A basic function in Dart uses the `void` keyword when it doesn't return a value:

```dart theme={null}
void saludar() {
  print('Hola, Estoy usando Funciones Básicas en Dart');
}
```

### Key Components

* **Return type**: `void` indicates the function doesn't return a value
* **Function name**: `saludar` - should be descriptive of what the function does
* **Parentheses**: `()` - contains parameters (empty in this case)
* **Body**: Code block enclosed in curly braces `{}`

## Calling Functions

To execute a function, simply use its name followed by parentheses:

```dart theme={null}
void main() {
  // Call the function once
  saludar();
  
  // Call the function multiple times in a loop
  for (var i = 0; i < 10; i++) {
    saludar();
  }
}
```

## Multiple Functions

You can define multiple functions in your program:

```dart theme={null}
void saludar() {
  print('Hola, Estoy usando Funciones Básicas en Dart');
}

void imprimirBienvenida() {
  print('Bienvenido a el uso de Funciones Básicas');
}

void main() {
  saludar();
  imprimirBienvenida();
}
```

<Note>
  Functions must be defined before they are called, or they can be called from within the `main()` function regardless of where they're defined in the file.
</Note>

## Complete Example

```dart theme={null}
// Función SIN retorno
void saludar() {
  print('Hola, Estoy usando Funciones Básicas en Dart');
}

void imprimirBienvenida(){
  print('Bienvenido a el uso de Funciones Básicas');
}

void main() {
  // Llama función sin retorno
  saludar();          

  for (var i = 0; i < 10; i++) {
    saludar();
  }

  imprimirBienvenida();
}
```

## Benefits of Functions

<CardGroup cols={2}>
  <Card title="Code Reusability" icon="recycle">
    Write once, use multiple times throughout your program
  </Card>

  <Card title="Better Organization" icon="folder-tree">
    Group related code together for easier maintenance
  </Card>

  <Card title="Improved Readability" icon="book-open">
    Make code more understandable with descriptive function names
  </Card>

  <Card title="Easier Testing" icon="vial">
    Test individual functions independently
  </Card>
</CardGroup>

## Best Practices

<Tip>
  * Use descriptive names that clearly indicate what the function does
  * Keep functions focused on a single task
  * Use `void` for functions that don't need to return a value
</Tip>

<Warning>
  Avoid creating functions that are too long or do too many things. If a function becomes complex, consider breaking it into smaller functions.
</Warning>
