Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fr tour nested methods #2254

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion _fr/tour/nested-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,34 @@ layout: tour
title: Nested Methods
partof: scala-tour

num: 8
num: 11

language: fr

next-page: multiple-parameter-lists
previous-page: higher-order-functions
---

En Scala il est possible d'empiler les définitions de méthode. L'objet suivant fourni une méthode `factorial` pour calculer la factorielle d'un nombre donnée :

{% scalafiddle %}
```scala mdoc
def factorial(x: Int): Int = {
def fact(x: Int, accumulator: Int): Int = {
if (x <= 1) accumulator
else fact(x - 1, x * accumulator)
}
fact(x, 1)
}

println("Factorial of 2: " + factorial(2))
println("Factorial of 3: " + factorial(3))
```
{% endscalafiddle %}

La sortie de ce programme est :

```
Factorial of 2: 2
Factorial of 3: 6
```