The value of the result of the for repeat statement in Playground during swift study is strange.

Asked 2 years ago, Updated 2 years ago, 67 views

I am studying swift.

I'm asking you a question because it's weird to use the for statement to practice the book example with playground.

for var i = 0; i < 10; i++ {
    print("\(i) execute")
}

Result value is

9 execute

That's what it says.

The result I expected was

0 execute
.
.
.
9 execute

It was.

Is something different on Playground?

This is my Playground screen. ​

swift for swift-playground

2022-09-21 19:24

2 Answers

In the image above, if you hover your mouse over where it says (10 times), you'll see a quickLook and the Show Result next to it.

Click on the round Show Result and you will see the following results.

0 execute
.
.
.
9 execute

In conclusion, playground is no different.


2022-09-21 19:24

[Self-answer]

Press the right mouse button at the part where the result is shown The menus Latest Value and Value History appear.

There must be a separate option.


2022-09-21 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.