Start learning free

LESSON 166 OF 679 · LOOPS & CONDITIONALS

Print Positive / Negative: Buggy Code in Rust

Practice

Inside the code editor we've tried to write a function that takes a vector nums as argument and for every number in the vector:

  • prints "negative" if that number is less than zero

  • or prints the number itself, if the number is greater than or equal to zero

So when we called the function for vec![2, -12, 0, 4, -5, 3], we expected it to print:

2
negative
0
4
negative
3

but it seems like we made some mistakes because when we run our code, it produces this output:

positive
2
-12
0
positive
4
-5
positive
3

Assignment:

Your task is to fix our loop such that it will print the desired output.

STEP 1 OF 1
    Ctrl + Enter to check