Skip to content

If expressions update #550

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

Closed
wants to merge 9 commits into from
24 changes: 22 additions & 2 deletions concepts.wip/if-expressions/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,30 @@ In Julia, like many other languages, allow for the following with `if`-expressio
- Nested if-expressions

~~~~exercism/note
`if`-expressions as defined here will encompass the following syntaxes:`if`, `if-else` and `if-elseif-else` statements.
[`if`-expressions](https://docs.julialang.org/en/v1/manual/control-flow/#man-conditional-evaluation) as defined here will encompass the following syntaxes:`if`, `if-else` and `if-elseif-else` statements.
~~~~

`if`-expressions allows for branching in our programs, given a conditional is satisfied.
`if`-expressions allows for branching in our programs, given a condition is satisfied.

## A prompt program example

Suppose you've defined a `password_checker(password)` function that returns `true`, if the password entered by the user is correct.

```julia
# Login prompt
println("Enter Password: ")

# Get user input
password = readline()

# Our main logic
if password_checker(password)
println("Welcome!")
end
```
Although the above program is not very realistic, but it shows the anatomy of an `if` statement.

In this case the `println("Welcome!")` is run, if the `password_checker(password)` returns `true`, otherwise it is skipped.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly a personal view, not an Exercism view, even though some other maintainers agree:

Imho any examples with reading input or printing anything should be avoided completely. So many people new to programming struggle with understanding the difference between printing and returning a value, often because their introductory classes or texts use printing everywhere. This is even more confusing in REPL settings where the difference is visually indistinguishable. To avoid this, I'd only print in an exercise that's explicitly about IO, not general examples or other exercises.

The example itself works but perhaps it could be turned into a function password_check(password)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for explaining this. Understood, I've converted the example into a function, as suggested. Please let me know if the example is clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's clearer, though I'd change it to return a string


We can do the following for effective branching:

Expand Down